#include "ModbusFactory.h"

#include "ComStruct.h"
#include "rtdb.h"
#include "ProjectMode.h"
#include "LogFile.h"
#include "ModbusAddress.h"
#include "DatetimeUtil.h"
#include "FunctionCode.h"
#include "RegisterAddress.h"

#ifdef XNLINUX
#include <unistd.h>
#include <time.h>
#include <sys/wait.h>
#endif

CModbusFactory::CModbusFactory()
{
	
}

CModbusFactory::~CModbusFactory()
{

}

void CModbusFactory::SetRtdb(CRTDB* pRtdb)
{
    m_pRtdb = pRtdb;
}

void CModbusFactory::SetProjectMode(int iProjectMode)
{
    m_iProjectMode = iProjectMode;
}

// >= 0 OK 
// -1 准备失败 
// -2 最后了 
// -3 参数错误 
int CModbusFactory::prepareDatagram(int iIndexStep, char* pSendDataBuf, uchar uaAddr)
{
	if (iIndexStep < 0 || 0 == pSendDataBuf)
	{
		return -3;
	}

    int iLenVal = 0;
	memset(pSendDataBuf, 0, SNED_BUFFER_LENGHT);

	switch (iIndexStep)
	{
    case 0:
        iLenVal = formDatagram(1/*读取告警状态*/, uaAddr, 2, 1, 52, pSendDataBuf); //离散输入寄存器 1~52
		break;
    case 1:
        iLenVal = formDatagram(8/*读取电池1~50 电压*/, uaAddr, 4, 1, 100, pSendDataBuf); //输入寄存器 1~99
		break;
    case 2:
        iLenVal = formDatagram(9/*读取电池51~100电压*/, uaAddr, 4, 101, 100, pSendDataBuf); //输入寄存器 101~199
		break;
    case 3:
        iLenVal = formDatagram(10/*读取电池101~150电压*/, uaAddr, 4, 201, 100, pSendDataBuf); //输入寄存器 201~299
		break;
    case 4:
        iLenVal = formDatagram(11/*读取电池151~200电压*/, uaAddr, 4, 301, 100, pSendDataBuf); //输入寄存器 301~399
		break;
    case 5:
        iLenVal = formDatagram(12/*读取电池201~250电压*/, uaAddr, 4, 401, 100, pSendDataBuf); //输入寄存器 401~499
		break;
    case 6:
        iLenVal = formDatagram(13/*读取电池251~300电压*/, uaAddr, 4, 501, 100, pSendDataBuf); //输入寄存器 501~599
		break;
    case 7:
        iLenVal = formDatagram(14/*读取电池301~350电压*/, uaAddr, 4, 601, 100, pSendDataBuf); //输入寄存器 601~699
		break;
    case 8:
        iLenVal = formDatagram(15/*读取电池350~400电压*/, uaAddr, 4, 701, 100, pSendDataBuf); //输入寄存器 701~799
		break;
    case 9:
        iLenVal = formDatagram(16/*读取电池1~50 温度*/, uaAddr, 4, 801, 100, pSendDataBuf); //输入寄存器 801~899
		break;
    case 10:
        iLenVal = formDatagram(17/*读取电池51~100温度*/, uaAddr, 4, 901, 100, pSendDataBuf); //输入寄存器 901~999
		break;
    case 11:
        iLenVal = formDatagram(18/*读取电池101~150温度*/, uaAddr, 4, 1001, 100, pSendDataBuf); //输入寄存器 1001~1099
		break;
    case 12:
        iLenVal = formDatagram(19/*读取电池151~200温度*/, uaAddr, 4, 1101, 100, pSendDataBuf); //输入寄存器 1101~1199
		break;
    case 13:
        iLenVal = formDatagram(20/*读取电池201~250温度*/, uaAddr, 4, 1201, 100, pSendDataBuf); //输入寄存器 1201~1299
		break;
    case 14:
        iLenVal = formDatagram(21/*读取电池251~300温度*/, uaAddr, 4, 1301, 100, pSendDataBuf); //输入寄存器 1301~1399
		break;
    case 15:
        iLenVal = formDatagram(22/*读取电池301~350温度*/, uaAddr, 4, 1401, 100, pSendDataBuf); //输入寄存器 1401~1499
		break;
    case 16:
        iLenVal = formDatagram(23/*读取电池350~400温度*/, uaAddr, 4, 1501, 100, pSendDataBuf); //输入寄存器 1501~1599
		break;
    case 17:
        iLenVal = formDatagram(24/*读取电池1~50 Soc*/, uaAddr, 4, 1601, 100, pSendDataBuf); //输入寄存器 1601~1699
		break;
    case 18:
        iLenVal = formDatagram(25/*读取电池51~100Soc*/, uaAddr, 4, 1701, 100, pSendDataBuf); //输入寄存器 1701~1799
		break;
    case 19:
        iLenVal = formDatagram(26/*读取电池101~150Soc*/, uaAddr, 4, 1801, 100, pSendDataBuf); //输入寄存器 1801~1899
		break;
    case 20:
        iLenVal = formDatagram(27/*读取电池151~200Soc*/, uaAddr, 4, 1901, 100, pSendDataBuf); //输入寄存器 1901~1999
		break;
    case 21:
        iLenVal = formDatagram(28/*读取电池201~250Soc*/, uaAddr, 4, 2001, 100, pSendDataBuf); //输入寄存器 2001~2099
		break;
    case 22:
        iLenVal = formDatagram(29/*读取电池251~300Soc*/, uaAddr, 4, 2101, 100, pSendDataBuf); //输入寄存器 2101~2199
		break;
    case 23:
        iLenVal = formDatagram(30/*读取电池301~350Soc*/, uaAddr, 4, 2201, 100, pSendDataBuf); //输入寄存器 2201~2299
		break;
    case 24:
        iLenVal = formDatagram(31/*读取电池350~400Soc*/, uaAddr, 4, 2301, 100, pSendDataBuf); //输入寄存器 2301~2399
		break;
    case 25:
        iLenVal = formDatagram(32/*读取电池1~50 内阻*/, uaAddr, 4, 2401, 100, pSendDataBuf); //输入寄存器 2401~2499
		break;
    case 26:
        iLenVal = formDatagram(33/*读取电池51~100内阻*/, uaAddr, 4, 2501, 100, pSendDataBuf); //输入寄存器 2501~2599
		break;
    case 27:
        iLenVal = formDatagram(34/*读取电池101~150内阻*/, uaAddr, 4, 2601, 100, pSendDataBuf); //输入寄存器 2601~2699
		break;
    case 28:
        iLenVal = formDatagram(35/*读取电池151~200内阻*/, uaAddr, 4, 2701, 100, pSendDataBuf); //输入寄存器 2701~2799
		break;
    case 29:
        iLenVal = formDatagram(36/*读取电池201~250内阻*/, uaAddr, 4, 2801, 100, pSendDataBuf); //输入寄存器 2801~2899
		break;
    case 30:
        iLenVal = formDatagram(37/*读取电池251~300内阻*/, uaAddr, 4, 2901, 100, pSendDataBuf); //输入寄存器 2901~2999
		break;
    case 31:
        iLenVal = formDatagram(38/*读取电池301~350内阻*/, uaAddr, 4, 3001, 100, pSendDataBuf); //输入寄存器 3001~3099
		break;
    case 32:
        iLenVal = formDatagram(39/*读取电池350~400内阻*/, uaAddr, 4, 3101, 100, pSendDataBuf); //输入寄存器 3101~3199
		break;
    case 33:
        iLenVal = formDatagram(40/*读取电池1~50 Soh*/, uaAddr, 4, 3201, 100, pSendDataBuf); //输入寄存器 3201~3299
		break;
    case 34:
        iLenVal = formDatagram(41/*读取电池51~100Soh*/, uaAddr, 4, 3301, 100, pSendDataBuf); //输入寄存器 3301~3399
		break;
    case 35:
        iLenVal = formDatagram(42/*读取电池101~150Soh*/, uaAddr, 4, 3401, 100, pSendDataBuf); //输入寄存器 3401~3499
		break;
    case 36:
        iLenVal = formDatagram(43/*读取电池151~200Soh*/, uaAddr, 4, 3501, 100, pSendDataBuf); //输入寄存器 3501~3599
		break;
    case 37:
        iLenVal = formDatagram(44/*读取电池201~250Soh*/, uaAddr, 4, 3601, 100, pSendDataBuf); //输入寄存器 3601~3699
		break;
    case 38:
        iLenVal = formDatagram(45/*读取电池251~300Soh*/, uaAddr, 4, 3701, 100, pSendDataBuf); //输入寄存器 3701~3799
		break;
    case 39:
        iLenVal = formDatagram(46/*读取电池301~350Soh*/, uaAddr, 4, 3801, 100, pSendDataBuf); //输入寄存器 3801~3899
		break;
    case 40:
        iLenVal = formDatagram(47/*读取电池350~400Soh*/, uaAddr, 4, 3901, 100, pSendDataBuf); //输入寄存器 3901~3999
		break;
    case 41:
        iLenVal = formDatagram(48/*读取其他浮点数*/, uaAddr, 4, 4001, 56, pSendDataBuf); //输入寄存器 4001~4055
		break;
    case 42:
        iLenVal = formDatagram(49/*读取其他短整形数*/, uaAddr, 4, 5001, 25, pSendDataBuf); //输入寄存器 5001~5025
		break;
	case 200:
        iLenVal = formDatagram(200, uaAddr, 4, 1, 100, pSendDataBuf); //采集BA中的通用输入寄存器
		break;
	case 201:
        iLenVal = formDatagram(201, uaAddr, 4, 1, 87, pSendDataBuf); //电池堆信息
		break;
	case 202:
        iLenVal = formDatagram(202, uaAddr, 3, 1, 8, pSendDataBuf); //电池堆保持寄存器
		break;
	case 203:
        iLenVal = formDatagram(203, uaAddr, 3, 1, 44, pSendDataBuf); //电池簇保持寄存器
		break;
	default:
		iLenVal = -2;
		break;
	}

	return iLenVal;
}

// >= 0 OK 
// -1 准备失败 
// -2 最后了 
// -3 参数错误 
//int CModbusFactory::prepareSetHoldDatagram(int iSetHoldRegStep, CBattStack* pStack, CBattBank* pBattBank, SAlarmParam* pAlarmParam, char* pSendDataBuf)
//{
//	if (iSetHoldRegStep < 0 || 0 == pSendDataBuf)
//	{
//		return -3;
//	}
//
//	// some varibales
//	int iLenVal = 0;
//	quint16 usTemp = 0;
//
//	memset(pSendDataBuf, 0, SNED_BUFFER_LENGHT);
//
//	switch (iSetHoldRegStep) 
//	{
//	case 301: //设置电池堆保持寄存器
//		if (pStack)
//		{
//			usTemp = 301;
//			addParam2Buffer(pSendDataBuf, usTemp);
//			iLenVal += 2;
//
//			iLenVal += 2; //协议标识
//
//			usTemp = 9; //长度
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 1; //Addr
//			iLenVal += 1;
//
//			*(pSendDataBuf + iLenVal) = 16; //Func Code
//			iLenVal += 1;
//
//			usTemp = 1; //Start Reg Addr
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			usTemp = 1; //Reg Num
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 2; //Byte Num
//			iLenVal += 1;
//			                         
//			addParam2Buffer(pSendDataBuf + iLenVal, pStack->usDelayBeforeCutCntor); //Value
//			iLenVal += 2;
//		}
//		else
//		{
//			iLenVal = -3;
//		}
//		break;
//	case 302: //设置预警参数
//		if (pBattBank && pAlarmParam)
//		{
//			usTemp = 302;
//			addParam2Buffer(pSendDataBuf, usTemp);
//			iLenVal += 2;
//
//			iLenVal += 2; //协议标识
//
//			usTemp = 31; //长度
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = pBattBank->uaModbusAddr; //Addr
//			iLenVal += 1;
//
//			*(pSendDataBuf + iLenVal) = 16; //Func Code
//			iLenVal += 1;
//
//			usTemp = 1; //Start Reg Addr
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			usTemp = 12; //Reg Num
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 24; //Byte Num
//			iLenVal += 1;
//
//			// Value
//			for (usTemp = 1; usTemp <= 12; ++usTemp) //寄存器
//			{
//				addHoldRegVal2BufferAlarm(pSendDataBuf + iLenVal, usTemp, pAlarmParam, pBattBank);
//				iLenVal += 2;
//			}
//		}
//		else
//		{
//			iLenVal = -3;
//		}
//		break;
//	case 303: //设置告警参数
//		if (pBattBank && pAlarmParam)
//		{
//			usTemp = 303;
//			addParam2Buffer(pSendDataBuf, usTemp);
//			iLenVal += 2;
//
//			iLenVal += 2; //协议标识
//
//			usTemp = 31; //长度
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = pBattBank->uaModbusAddr; //Addr
//			iLenVal += 1;
//
//			*(pSendDataBuf + iLenVal) = 16; //Func Code
//			iLenVal += 1;
//
//			usTemp = 13; //Start Reg Addr
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			usTemp = 12; //Reg Num
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 24; //Byte Num
//			iLenVal += 1;
//
//			// Value
//			for (usTemp = 13; usTemp <= 24; ++usTemp) //寄存器
//			{
//				addHoldRegVal2BufferAlarm(pSendDataBuf + iLenVal, usTemp, pAlarmParam, pBattBank);
//				iLenVal += 2;
//			}
//		}
//		else
//		{
//			iLenVal = -3;
//		}
//		break;
//	case 304: //设置保护参数
//		if (pBattBank && pAlarmParam)
//		{
//			usTemp = 304;
//			addParam2Buffer(pSendDataBuf, usTemp);
//			iLenVal += 2;
//
//			iLenVal += 2; //协议标识
//
//			usTemp = 31; //长度
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = pBattBank->uaModbusAddr; //Addr
//			iLenVal += 1;
//
//			*(pSendDataBuf + iLenVal) = 16; //Func Code
//			iLenVal += 1;
//
//			usTemp = 25; //Start Reg Addr
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			usTemp = 12; //Reg Num
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 24; //Byte Num
//			iLenVal += 1;
//
//			// Value
//			for (usTemp = 25; usTemp <= 36; ++usTemp) //寄存器
//			{
//				addHoldRegVal2BufferAlarm(pSendDataBuf + iLenVal, usTemp, pAlarmParam, pBattBank);
//				iLenVal += 2;
//			}
//		}
//		else
//		{
//			iLenVal = -3;
//		}
//		break;
//	case 305: //设置调整步长
//		if (pBattBank && pAlarmParam)
//		{
//			usTemp = 305;
//			addParam2Buffer(pSendDataBuf, usTemp);
//			iLenVal += 2;
//
//			iLenVal += 2; //协议标识
//
//			usTemp = 23; //长度
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = pBattBank->uaModbusAddr; //Addr
//			iLenVal += 1;
//
//			*(pSendDataBuf + iLenVal) = 16; //Func Code
//			iLenVal += 1;
//
//			usTemp = 37; //Start Reg Addr
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			usTemp = 8; //Reg Num
//			addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
//			iLenVal += 2;
//
//			*(pSendDataBuf + iLenVal) = 16; //Byte Num
//			iLenVal += 1;
//
//			// Value
//			for (usTemp = 37; usTemp <= 44; ++usTemp) //寄存器
//			{
//				addHoldRegVal2BufferAlarm(pSendDataBuf + iLenVal, usTemp, pAlarmParam, pBattBank);
//				iLenVal += 2;
//			}
//		}
//		else
//		{
//			iLenVal = -3;
//		}
//		break;
//	default:
//		iLenVal = -2;
//		break;
//	}
//
//	return iLenVal;
//}

int CModbusFactory::addParam2Buffer(char* pData, quint32 uiParamVal)
{
	*pData = (char)(uiParamVal >> 24);

	++pData;
	*pData = (char)(uiParamVal >> 16);

	++pData;
	*pData = (char)(uiParamVal >> 8);

	++pData;
	*pData = (char)(uiParamVal);

    return 0;
}

int CModbusFactory::addParam2Buffer(char* pData, quint16 uiParamVal)
{
	*pData = (char)(uiParamVal >> 8);

	++pData;
	*pData = (char)(uiParamVal);

    return 0;
}

int CModbusFactory::addParam2Buffer(char* pData, float fParamVal)
{
	char aTemp[4];
	memcpy(aTemp, (char*)&fParamVal, 4);
	
	*pData = aTemp[3];
	++pData;
	*pData = aTemp[2];
	++pData;
	*pData = aTemp[1];
	++pData;
	*pData = aTemp[0];
	
	return 0;
}

int CModbusFactory::getParamFromBuffer(char* pData, quint16& uiParamVal)
{
	uiParamVal = (unsigned char)*pData;
	uiParamVal = uiParamVal * 256;

	++pData;

	uiParamVal += (unsigned char)*pData;

	return 0;
}

int CModbusFactory::getParamFromBuffer(char* pData, quint32& uiParamVal)
{
	uiParamVal = (unsigned char)*pData;

	uiParamVal = uiParamVal * 256;
	++pData;
	uiParamVal += (unsigned char)*pData;

	uiParamVal = uiParamVal * 256;
	++pData;
	uiParamVal += (unsigned char)*pData;

	uiParamVal = uiParamVal * 256;
	++pData;
	uiParamVal += (unsigned char)*pData;

	return 0;
}

int CModbusFactory::getParamFromBuffer(char* pData, float& fParamVal)
{
	char aTemp[4];
	aTemp[3] = *pData;
	++pData;
	aTemp[2] = *pData;
	++pData;
	aTemp[1] = *pData;
	++pData;
	aTemp[0] = *pData;

	memcpy(&fParamVal, aTemp, 4);
	return 0;
}

int CModbusFactory::formDatagram(quint16 usEvent, uchar uaAddr, uchar uaFuncCode, quint16 usStartReg, quint16 usRegNum, char* pSendDataBuf)
{
	int iLenVal = 0;
	quint16 usTemp = 0;

	addParam2Buffer(pSendDataBuf, usEvent);
	iLenVal += 2;

    iLenVal += 2; //协议标识

    usTemp = 6; //长度
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pSendDataBuf + iLenVal) = uaAddr;
	iLenVal += 1;

	*(pSendDataBuf + iLenVal) = uaFuncCode;
	iLenVal += 1;

	usTemp = usStartReg;
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	usTemp = usRegNum;
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	return iLenVal;
}

int CModbusFactory::formHoldRegDatagram(quint16 usEvent, uchar uaAddr, quint16 usStartReg, quint16 usRegNum, char* pSendDataBuf, float* pFVal)
{
	// some variables
	int iLenVal = 0;
	quint16 usTemp = 0;

	if (0 != usRegNum % 2)
	{
        --usRegNum; //变成偶数
	}

	addParam2Buffer(pSendDataBuf, usEvent);
	iLenVal += 2;

    iLenVal += 2; //协议标识

    usTemp = usRegNum * 2 + 7; //长度
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pSendDataBuf + iLenVal) = uaAddr;
	iLenVal += 1;

	*(pSendDataBuf + iLenVal) = 0x10;
	iLenVal += 1;

	usTemp = usStartReg;
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	usTemp = usRegNum;
	addParam2Buffer(pSendDataBuf + iLenVal, usTemp);
	iLenVal += 2;

    *(pSendDataBuf + iLenVal) = (quint8)(usRegNum * 2); //长度
	iLenVal += 1;

	for (int i = 0; i < usRegNum / 2; ++i)
	{
		addParam2Buffer(pSendDataBuf + iLenVal, *pFVal);
		++pFVal;
		iLenVal += 4;
	}

	return iLenVal;
}

// >= 0 OK 返回值
// -1 参数错误
// -2 长度不正确
// -3 功能码不正确

// < 0 处理失败
int CModbusFactory::analyReqDatagram(char* pDataBuf, int iLen, SMdobusTcpReq& req)
{
    if (0 == pDataBuf)
	{
        KG_LOG_INFO(QString("数据缓冲区指针无效"));
		return -1;
	}

    if (iLen < 12)
    {
        KG_LOG_INFO(QString("数据缓冲区长度不足12字节"));
        return -1;
    }

	req.usEvent = 0;
	req.usProto = 0;
	req.usLen = 0;
	req.uaAddr = 0;
	req.uaFuncCode = 0;
	req.usRegAddr = 0;
	req.usRegNum = 0;

	// Read Data
	int iInedx = 0;

	getParamFromBuffer(pDataBuf, req.usEvent);
	iInedx += 2;

	getParamFromBuffer(pDataBuf + iInedx, req.usProto);
	iInedx += 2;

	getParamFromBuffer(pDataBuf + iInedx, req.usLen);
	iInedx += 2;

	req.uaAddr = (uchar)*(pDataBuf + iInedx);
	iInedx += 1;

	req.uaFuncCode = (uchar)*(pDataBuf + iInedx);
	iInedx += 1;

	getParamFromBuffer(pDataBuf + iInedx, req.usRegAddr);
	iInedx += 2;

	getParamFromBuffer(pDataBuf + iInedx, req.usRegNum);
	iInedx += 2;

	// 校验报文是否正确
    if (2 == req.uaFuncCode || 4 == req.uaFuncCode || 3 == req.uaFuncCode || 6 == req.uaFuncCode) //功能码 0x02 0x04 0x03 0x06
	{
		if (req.usLen != 6)
		{
            KG_LOG_INFO(QString("长度不等于6,功能码为%1").arg((int)req.uaFuncCode));
			return -2;
		}
	}
    else if (17 == req.uaFuncCode) //0x11
	{
		if (req.usLen < 6)
		{
            KG_LOG_INFO(QString("长度小于6,功能码为%1").arg((int)req.uaFuncCode));
			return -2;
		}
	}
    else if (16 == req.uaFuncCode) //功能码 0x10
	{
        int iByteNum = (uchar)*(pDataBuf + iInedx); //后续字节数
		iInedx += 1;

        if (req.usRegNum * 2 != iByteNum || req.usLen != req.usRegNum * 2 + 7 || iLen < req.usLen + 6) //iLen >= req.usLen + 6
		{
            KG_LOG_INFO(QString("字节长度不相等,功能码为%1").arg((int)req.uaFuncCode));
			return -2;
		}
	}
	else 
	{
		return -3;
	}

    QString strLog = "";
    strLog += QString("事务类型%1").arg(req.usEvent, 4, 16);
    strLog += QString(" 协议标识%1").arg(req.usProto, 4, 16);
    strLog += QString(" 长度%1").arg(req.usLen, 2, 16);
    strLog += QString(" 地址%1").arg(req.uaAddr, 2, 16);
    strLog += QString(" 功能码%1").arg(req.uaFuncCode, 2, 16);
    strLog += QString(" 寄存器地址%1").arg(req.usRegAddr, 4, 16);
    strLog += QString(" 寄存器长度%1").arg(req.usRegNum, 4, 16);
    KG_LOG_INFO(strLog);

	return 0;
}

// >= 0 OK 
// -1 参数错误 
// -2 功能码错误 
// -3 超出范围
int CModbusFactory::prepareBattDatagram(char* pDataBuf, SMdobusTcpReq* pReq, CBattBank* pBattBank)
{
	// some variables
    int iByteNum = 0;

	if (0 == pDataBuf || 0 == pReq || 0 == pBattBank)
	{
		return -1;
	}

    if (CFunctionCode::READ_04_INPUT_REGISTERS == pReq->uaFuncCode)
	{
		iByteNum = pReq->usRegNum * 2;

        if (iByteNum > 255) //超出范围
		{
			return -3;
		}
	}
    else if (CFunctionCode::READ_02_INPUT == pReq->uaFuncCode)
	{
		if (0 == pReq->usRegNum % 8)
		{
			iByteNum = pReq->usRegNum / 8;
		}
		else
		{
			iByteNum = pReq->usRegNum / 8 + 1;
		}

        if (iByteNum > 255) //超出范围
		{
			return -3;
		}
	}
	else
	{
		return -2;
	}
	
	// Head
    int iLenVal = 0;
	quint16 usRetRegNum = 0;
	memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

	// some variables  
	// 计算字节数
	quint16 usTemp = 0;

	addParam2Buffer(pDataBuf, pReq->usEvent);
    iLenVal += 2; //事务标识

	addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
    iLenVal += 2; //协议标识

    usTemp = (quint16)(iByteNum + 3); //长度,3=1单元标识/Modbus地址+1功能码+1字节数
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = pReq->uaAddr;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = pReq->uaFuncCode;
	iLenVal += 1;

    *(pDataBuf + iLenVal) = (uchar)(iByteNum); //字节数
	iLenVal += 1;

    if (CFunctionCode::READ_02_INPUT == pReq->uaFuncCode) //离散
	{
        for (quint16 usIndex = 0; usIndex < pReq->usRegNum;) //离散寄存器
		{
			addRegVal2BufferBankDis(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattBank);

			usIndex += 8;

            iLenVal += 1;
		}
	}
	else
	{
        for (quint16 usIndex = 0; usIndex < pReq->usRegNum;) //寄存器
		{
			usRetRegNum = addRegVal2BufferBank(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattBank);

			iLenVal += usRetRegNum * 2;

			usIndex += usRetRegNum;
		}
	}
	
	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 类型错误 
// -3 无告警缓存
int CModbusFactory::prepareAlarmCacheDatagram(char* pDataBuf, SMdobusTcpReq* pReq, CBattBank* pBattBank, CBankAlarm* pBankAlarm)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pBattBank || 0 == pBankAlarm)
	{
		return -1;
	}

	// some variables
	SAlarmCache* pAlarmCache = 0;

    if (1 == pReq->usRegAddr) //类型 1-请求 2-确认
	{
		if (pBattBank->aAlarmAvailable > 0 && (pBankAlarm->usFirstCacheNo != pBankAlarm->usLastCacheNo))
		{
            pAlarmCache = &(pBankAlarm->alarmCache[pBankAlarm->usFirstCacheNo]);
		}
		else 
		{
			return -3;
		}
	}
	else if (2 == pReq->usRegAddr)
	{
        if (pBankAlarm->usFirstCacheNo == pReq->usRegNum) //告警缓存序号
		{
			// 调整索引
			if (pBankAlarm->usFirstCacheNo >= MAX_ALARM_CACHE_NUM - 1)
			{
				pBankAlarm->usFirstCacheNo = 0;
			}
			else
			{
				++pBankAlarm->usFirstCacheNo;
			}
		}

		if (pBattBank->aAlarmAvailable > 0 && (pBankAlarm->usFirstCacheNo != pBankAlarm->usLastCacheNo))
		{
            pAlarmCache = &(pBankAlarm->alarmCache[pBankAlarm->usFirstCacheNo]);
		}
		else 
		{
			return 0;
		}
	}
	else
	{
		return -2;
	}

    if (0 == pAlarmCache)
	{
		return -3;
	}

	// Head
    int iLenVal = 0;
	quint16 usTemp = 0;

	memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

	addParam2Buffer(pDataBuf, pReq->usEvent);
    iLenVal += 2; //事务标识

	addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
    iLenVal += 2; //协议标识

    usTemp = 30; //长度
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = pReq->uaAddr;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = pReq->uaFuncCode;
	iLenVal += 1;

    *(pDataBuf + iLenVal) = 27; //字节数
	iLenVal += 1;

    usTemp = pBankAlarm->usFirstCacheNo; //告警编码
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

    usTemp = pAlarmCache->usYear; //告警时间-年
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

    *(pDataBuf + iLenVal) = (char)(pAlarmCache->usMonth); //告警时间-月
	iLenVal += 1;

    *(pDataBuf + iLenVal) = (char)(pAlarmCache->usDay); //告警时间-日
	iLenVal += 1;

    *(pDataBuf + iLenVal) = (char)(pAlarmCache->usHour); //告警时间-时
	iLenVal += 1;

    *(pDataBuf + iLenVal) = (char)(pAlarmCache->usMin); //告警时间-分
	iLenVal += 1;

    *(pDataBuf + iLenVal) = (char)(pAlarmCache->usSec); //告警时间-秒
	iLenVal += 1;

    usTemp = pAlarmCache->usMsec; //告警时间-毫秒
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

    *(pDataBuf + iLenVal) = (char)(pAlarmCache->usType); //离散寄存器地址
	iLenVal += 1;

    usTemp = pAlarmCache->usCellNo; //电池的单体号
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

    *(pDataBuf + iLenVal) = (char)(pAlarmCache->usAlmVal); //告警值 1 0--无告警，1--告警
	iLenVal += 1;

    addParam2Buffer(pDataBuf + iLenVal, pAlarmCache->fSampVal); //告警发生时采样值
	iLenVal += 4;

    addParam2Buffer(pDataBuf + iLenVal, pAlarmCache->fThreVal); //设置告警阈值
	iLenVal += 4;

    usTemp = pAlarmCache->usNo1; //序号1
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

    usTemp = pAlarmCache->usNo2; //序号2
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
    iLenVal += 2;

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 功能码错误 
// -3 超出范围
int CModbusFactory::prepareBankAlarmDatagram(char* pDataBuf, SMdobusTcpReq* pReq, SAlarmParam* pAlarmParam, CBattBank* pBattBank, CBattStack* pBattStack)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pAlarmParam || 0 == pBattBank || 0 == pBattStack)
	{
		return -1;
	}

	// some variables 
    int iLenVal = 0;
	quint16 usTemp = 0;

    if (CFunctionCode::READ_03_HOLD_REGISTERS == pReq->uaFuncCode) //读保持寄存器
	{
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
        iLenVal += 2; //事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
        iLenVal += 2; //协议标识

        if (pReq->usRegNum * 2 > 255) //超出范围
		{
			iLenVal = -4;
		}
		else
		{
            usTemp = pReq->usRegNum * 2 + 3; //长度,3=1单元标识/Modbus地址+1功能码+1字节数
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

            *(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); //字节数
			iLenVal += 1;

            for (quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) //寄存器
			{
				addHoldRegVal2BufferAlarm(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pAlarmParam, pBattBank);

				iLenVal += 2;
			}
		}
	}
    else if (CFunctionCode::WRITE_06_ONE_HOLD_REGISTER == pReq->uaFuncCode) //写保持寄存器(单)
	{
		// Data
		if (setAlarmHoldRegVal(pReq->usRegAddr, pReq->usRegNum, pAlarmParam, pBattBank, pBattStack) >= 0)
		{
			memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

			addParam2Buffer(pDataBuf, pReq->usEvent);
            iLenVal += 2; //事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
            iLenVal += 2; //协议标识

			usTemp = 6;
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
            iLenVal += 2; //长度

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
            iLenVal += 2; //寄存器地址

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
            iLenVal += 2; //寄存器值
		}
		else
		{
			iLenVal = -5;
		}
	}
    else if (CFunctionCode::WRITE_10_SOME_HOLD_REGISTERS == pReq->uaFuncCode) //写保持寄存器(多)
	{
		// Data
        iLenVal = 13; //2事务标识 + 2协议标识 + 2长度 + 1地址 + 1功能码 + 2寄存器地址 + 2寄存器个数 + 1字节数
        for (quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) //寄存器
		{
            getParamFromBuffer(pDataBuf + iLenVal, usTemp);

			if (setAlarmHoldRegVal(pReq->usRegAddr + usIndex, usTemp, pAlarmParam, pBattBank, pBattStack) < 0)
			{
				iLenVal = -5;
				break;
			}

			iLenVal += 2;
		}

		if (iLenVal > 0)
		{
			memset(pDataBuf, 0, SNED_BUFFER_LENGHT);
			addParam2Buffer(pDataBuf, pReq->usEvent);
            iLenVal = 2; //事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
            iLenVal += 2; //协议标识

			usTemp = 6;
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
            iLenVal += 2; //长度

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
            iLenVal += 2; //寄存器地址

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
            iLenVal += 2; //寄存器值
		}
	}
	else
	{
		iLenVal = -2;
	}

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 功能码错误 
// -3 地址超出范围
// -4 超出范围
// -5 设置保持寄存器错误
int CModbusFactory::prepareEnvDatagram(char* pDataBuf, SMdobusTcpReq* pReq, CBattStack* pBattStack, int iModbusAddress)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pBattStack)
	{
		return -1;
	}

	// some variables 
    int iLenVal = 0;
	quint16 usRetRegNum = 0;
	quint16 usTemp = 0;
	int iByteNum = 0;
	uchar uaVal = 0;

    if (CFunctionCode::READ_02_INPUT == pReq->uaFuncCode) //离散寄存器
	{
		if (0 == pReq->usRegNum % 8)
		{
			iByteNum = pReq->usRegNum / 8;
		}
		else
		{
			iByteNum = pReq->usRegNum / 8 + 1;
		}

        if (iByteNum > 255) //超出范围
		{
			return -3;
		}

		// 报文处理
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
        iLenVal += 2; //事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
        iLenVal += 2; //协议标识

        usTemp = (quint16)(iByteNum + 3); //长度,3=1单元标识/Modbus地址+1功能码+1字节数
		addParam2Buffer(pDataBuf + iLenVal, usTemp);
		iLenVal += 2;

		*(pDataBuf + iLenVal) = pReq->uaAddr;
		iLenVal += 1;

		*(pDataBuf + iLenVal) = pReq->uaFuncCode;
		iLenVal += 1;

        *(pDataBuf + iLenVal) = (uchar)(iByteNum); //字节数
		iLenVal += 1;

        for (quint16 usIndex = 0; usIndex < pReq->usRegNum;) //离散寄存器
		{
			// 一个字节处理
			uaVal = 0;
			for (quint16 usIndexReg = 0; usIndexReg < 8; ++usIndexReg)
			{
                if (getRegValEnvDis(iModbusAddress, pReq->usRegAddr + usIndex + usIndexReg, pBattStack) > 0)
				{
					uaVal = uaVal | 0x80;
				}

				// 移位
                if (usIndexReg < 7) //0 - 6
				{
					uaVal = uaVal >> 1;
				}
			}

			usIndex += 8;

			*(pDataBuf + iLenVal) = uaVal;
            iLenVal += 1;
		}
	}
    else if (CFunctionCode::READ_04_INPUT_REGISTERS == pReq->uaFuncCode || CFunctionCode::READ_03_HOLD_REGISTERS == pReq->uaFuncCode) //输入寄存器
	{
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
        iLenVal += 2; //事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
        iLenVal += 2; //协议标识

        //if (pReq->usRegAddr > 84) //寄存器地址超出范围
		//{
		//	return -3;
		//}

        if (pReq->usRegNum * 2 > 255) //超出范围
		{
            KG_LOG_INFO(QString("请求中的寄存器数量%1太大 乘2将大于255").arg(pReq->usRegNum));
			iLenVal = -4;
		}
		else
		{
            usTemp = pReq->usRegNum * 2 + 3; //长度,3=1单元标识/Modbus地址+1功能码+1字节数
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

            *(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); //字节数
			iLenVal += 1;

            for (quint16 usIndex = 0; usIndex < pReq->usRegNum;) //寄存器
			{
                usRetRegNum = addRegVal2BufferEnv(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattStack, iModbusAddress);

				iLenVal += usRetRegNum * 2;

				usIndex += usRetRegNum;
			}
		}
	}
    else if (CFunctionCode::WRITE_06_ONE_HOLD_REGISTER == pReq->uaFuncCode) //写保持寄存器(单)
    {
        int iDevIndex = iModbusAddress - CModbusAddress::ENV_DATA_MIN;
        if (pReq->usRegAddr >= AC_REG_SET_MIN && pReq->usRegAddr <= AC_REG_SET_MAX)
        {
            //下设空调的QUINT16类型值
            if (setEnvAcValue(iDevIndex, pReq->usRegAddr, pReq->usRegNum) >= 0)
            {
                memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

                addParam2Buffer(pDataBuf, pReq->usEvent);
                iLenVal += 2; //事务标识

                addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
                iLenVal += 2; //协议标识

                usTemp = 6;
                addParam2Buffer(pDataBuf + iLenVal, usTemp);
                iLenVal += 2; //长度

                *(pDataBuf + iLenVal) = pReq->uaAddr;
                iLenVal += 1;

                *(pDataBuf + iLenVal) = pReq->uaFuncCode;
                iLenVal += 1;

                addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
                iLenVal += 2; //寄存器地址

                addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
                iLenVal += 2; //寄存器值
            }
            else
            {
                iLenVal = -5;
            }
        }
        else if (pReq->usRegAddr >= LC_REG_SET_MIN && pReq->usRegAddr <= LC_REG_SET_MAX)
        {
            //下设液冷的QUINT16类型值
            if (setEnvLcValue(iDevIndex, pReq->usRegAddr, pReq->usRegNum) >= 0)
            {
                memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

                addParam2Buffer(pDataBuf, pReq->usEvent);
                iLenVal += 2; //事务标识

                addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
                iLenVal += 2; //协议标识

                usTemp = 6;
                addParam2Buffer(pDataBuf + iLenVal, usTemp);
                iLenVal += 2; //长度

                *(pDataBuf + iLenVal) = pReq->uaAddr;
                iLenVal += 1;

                *(pDataBuf + iLenVal) = pReq->uaFuncCode;
                iLenVal += 1;

                addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
                iLenVal += 2; //寄存器地址

                addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
                iLenVal += 2; //寄存器值
            }
            else
            {
                iLenVal = -5;
            }
        }
        else if (pReq->usRegAddr >= PCS_REG_SET_MIN && pReq->usRegAddr <= PCS_REG_SET_MAX)
        {
            //下设PCS的QUINT16类型值
            if (setEnvPcsValue(iDevIndex, pReq->usRegAddr, pReq->usRegNum) >= 0)
            {
                memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

                addParam2Buffer(pDataBuf, pReq->usEvent);
                iLenVal += 2; //事务标识

                addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
                iLenVal += 2; //协议标识

                usTemp = 6;
                addParam2Buffer(pDataBuf + iLenVal, usTemp);
                iLenVal += 2; //长度

                *(pDataBuf + iLenVal) = pReq->uaAddr;
                iLenVal += 1;

                *(pDataBuf + iLenVal) = pReq->uaFuncCode;
                iLenVal += 1;

                addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
                iLenVal += 2; //寄存器地址

                addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
                iLenVal += 2; //寄存器值
            }
            else
            {
                iLenVal = -5;
            }
        }
    }
	else
	{
		iLenVal = -2;
	}

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 功能码错误 
// -3 地址超出范围
// -4 超出范围
// -5 设置保持寄存器错误
int CModbusFactory::prepareStackDatagram(char* pDataBuf, SMdobusTcpReq* pReq, CBattStack* pBattStack)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pBattStack)
	{
		return -1;
	}

	// some variables 
    int iLenVal = 0;
	quint16 usRetRegNum = 0;
	quint16 usTemp = 0;
	int iByteNum = 0;
	uchar uaVal = 0;
	
    if (CFunctionCode::READ_02_INPUT == pReq->uaFuncCode) //离散寄存器
	{
		if (0 == pReq->usRegNum % 8)
		{
			iByteNum = pReq->usRegNum / 8;
		}
		else
		{
			iByteNum = pReq->usRegNum / 8 + 1;
		}

        if (iByteNum > 255) //超出范围
		{
			return -3;
		}

		// 报文处理
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
        iLenVal += 2; //事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
        iLenVal += 2; //协议标识

        usTemp = (quint16)(iByteNum + 3); //长度,3=1单元标识/Modbus地址+1功能码+1字节数
		addParam2Buffer(pDataBuf + iLenVal, usTemp);
		iLenVal += 2;

		*(pDataBuf + iLenVal) = pReq->uaAddr;
		iLenVal += 1;

		*(pDataBuf + iLenVal) = pReq->uaFuncCode;
		iLenVal += 1;

        *(pDataBuf + iLenVal) = (uchar)(iByteNum); //字节数
		iLenVal += 1;

        for (quint16 usIndex = 0; usIndex < pReq->usRegNum;) //离散寄存器
		{
			// 一个字节处理
			uaVal = 0;
			for (quint16 usIndexReg = 0; usIndexReg < 8; ++usIndexReg)
			{
				if (getRegValStackDis(pReq->usRegAddr + usIndex + usIndexReg, pBattStack) > 0)
				{
					uaVal = uaVal | 0x80;
				}

				// 移位
                if (usIndexReg < 7) //0 - 6
				{
					uaVal = uaVal >> 1;
				}
			}

			usIndex += 8;

			*(pDataBuf + iLenVal) = uaVal;
            iLenVal += 1;
		}
	}
    else if (CFunctionCode::READ_04_INPUT_REGISTERS == pReq->uaFuncCode) //输入寄存器
	{
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
        iLenVal += 2; //事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
        iLenVal += 2; //协议标识

        //if (pReq->usRegAddr > 84) //寄存器地址超出范围
		//{
		//	return -3;
		//}

        if (pReq->usRegNum * 2 > 255) //超出范围
		{
			iLenVal = -4;
		}
		else
		{
            usTemp = pReq->usRegNum * 2 + 3; //长度,3=1单元标识/Modbus地址+1功能码+1字节数
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

            *(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); //字节数
			iLenVal += 1;

            for (quint16 usIndex = 0; usIndex < pReq->usRegNum;) //寄存器
			{
				usRetRegNum = addRegVal2BufferStack(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattStack);

				iLenVal += usRetRegNum * 2;

				usIndex += usRetRegNum;
			}
		}
	}
    else if (CFunctionCode::READ_03_HOLD_REGISTERS == pReq->uaFuncCode) //读保持寄存器
	{
		memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

		addParam2Buffer(pDataBuf, pReq->usEvent);
        iLenVal += 2; //事务标识

		addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
        iLenVal += 2; //协议标识

        if (pReq->usRegNum * 2 > 255) //超出范围
		{
			iLenVal = -4;
		}
		else
		{
            usTemp = pReq->usRegNum * 2 + 3; //长度,3=1单元标识/Modbus地址+1功能码+1字节数
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

            *(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); //字节数
			iLenVal += 1;

            for (quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) //寄存器
			{
				addHoldRegVal2BufferStack(pDataBuf + iLenVal, pReq->usRegAddr + usIndex, pBattStack);

				iLenVal += 2;
			}
		}
	}
    else if (CFunctionCode::WRITE_06_ONE_HOLD_REGISTER == pReq->uaFuncCode) //写保持寄存器(单)
	{
		// Data
		if (setStackHoldRegVal(pReq->usRegAddr, pReq->usRegNum, pBattStack) >= 0)
		{
			memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

			addParam2Buffer(pDataBuf, pReq->usEvent);
            iLenVal += 2; //事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
            iLenVal += 2; //协议标识

			usTemp = 6;
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
            iLenVal += 2; //长度

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
            iLenVal += 2; //寄存器地址

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
            iLenVal += 2; //寄存器值
		}
		else
		{
			iLenVal = -5;
		}
	}
    else if (CFunctionCode::WRITE_10_SOME_HOLD_REGISTERS == pReq->uaFuncCode) //写保持寄存器(多)
	{
		// Data
        iLenVal = 13; //2事务标识 + 2协议标识 + 2长度 + 1地址 + 1功能码 + 2寄存器地址 + 2寄存器个数 + 1字节数
        for (quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) //寄存器
		{
            getParamFromBuffer(pDataBuf + iLenVal, usTemp);

			if (setStackHoldRegVal(pReq->usRegAddr + usIndex, usTemp, pBattStack) < 0)
			{
				iLenVal = -5;
				break;
			}

			iLenVal += 2;
		}

		if (iLenVal > 0)
		{
			memset(pDataBuf, 0, SNED_BUFFER_LENGHT);
			addParam2Buffer(pDataBuf, pReq->usEvent);
            iLenVal = 2; //事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
            iLenVal += 2; //协议标识

			usTemp = 6;
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
            iLenVal += 2; //长度

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegAddr);
            iLenVal += 2; //寄存器地址

			addParam2Buffer(pDataBuf + iLenVal, pReq->usRegNum);
            iLenVal += 2; //寄存器值
		}
	}
	else
	{
		iLenVal = -2;
	}

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误
int CModbusFactory::prepareExcepDatagram(char* pDataBuf, SMdobusTcpReq* pReq, uchar uaExcepCode)
{
	if (0 == pDataBuf || 0 == pReq)
	{
		return -1;
	}

    int iLenVal = 0;
	memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

	// some variables
	quint16 usTemp = 0;

	addParam2Buffer(pDataBuf, pReq->usEvent);
    iLenVal += 2; //事务标识

	addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
    iLenVal += 2; //协议标识

    usTemp = 3; //长度
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = pReq->uaAddr;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = (pReq->uaFuncCode + 0x80);
	iLenVal += 1;

	*(pDataBuf + iLenVal) = uaExcepCode;
	iLenVal += 1;

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 地址超出范围
// -3 功能码错误 
// -4 超出范围
// -5 写保持寄存器地址不正确
int CModbusFactory::prepareBAComHoldRegDatagram(char* pDataBuf, SMdobusTcpReq* pReq, quint16* pComHoldRegData)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pComHoldRegData)
	{
		return -1;
	}

    if (pReq->usRegAddr > 50 || pReq->usRegAddr < 1) //寄存器地址超出范围
	{
		return -2;
	}

	// Head
    int iLenVal = 0;
	memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

	// some variables  
	// 计算字节数
	quint16 usTemp = 0;

    if (CFunctionCode::READ_03_HOLD_REGISTERS == pReq->uaFuncCode) //读保持寄存器
	{
        if (pReq->usRegNum * 2 > 255) //超出范围
		{
			iLenVal = -4;
		}
		else
		{
			addParam2Buffer(pDataBuf, pReq->usEvent);
            iLenVal += 2; //事务标识

			addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
            iLenVal += 2; //协议标识

            usTemp = pReq->usRegNum * 2 + 3; //长度,3=1单元标识/Modbus地址+1功能码+1字节数
			addParam2Buffer(pDataBuf + iLenVal, usTemp);
			iLenVal += 2;

			*(pDataBuf + iLenVal) = pReq->uaAddr;
			iLenVal += 1;

			*(pDataBuf + iLenVal) = pReq->uaFuncCode;
			iLenVal += 1;

            *(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); //字节数
			iLenVal += 1;

			// data	
            for (quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) //寄存器
			{
				if (pReq->usRegAddr - 1 + usIndex < 50)
				{
					usTemp = *(pComHoldRegData + pReq->usRegAddr - 1 + usIndex);
				}
				else
				{
					usTemp = 0;
				}

				addParam2Buffer(pDataBuf + iLenVal, usTemp);
				iLenVal += 2;
			}
		}
	}
    else if (CFunctionCode::WRITE_06_ONE_HOLD_REGISTER == pReq->uaFuncCode) //写保持寄存器
	{
		iLenVal = pReq->usRegAddr - 1;

		if (iLenVal >= 0 && iLenVal < 50)
		{
			pComHoldRegData[iLenVal] = pReq->usRegNum;

			iLenVal = formDatagram(pReq->usEvent, pReq->uaAddr, pReq->uaFuncCode, pReq->usRegAddr, pReq->usRegNum, pDataBuf);
		}
		else
		{
			iLenVal = -5;
		}
	}
	else
	{
		return -3;
	}

	return iLenVal;
}

// >= 0 OK 
// -1 参数错误 
// -2 功能码错误 
// -3 地址超出范围
// -4 超出范围
int CModbusFactory::prepareBAComInputRegDatagram(char* pDataBuf, SMdobusTcpReq* pReq, quint16* pComInputRegData)
{
	if (0 == pDataBuf || 0 == pReq || 0 == pComInputRegData)
	{
		return -1;
	}

    if (CFunctionCode::READ_04_INPUT_REGISTERS != pReq->uaFuncCode) //输入寄存器 功能码
	{
		return -2;
	}

    if (pReq->usRegAddr > 100 || pReq->usRegAddr < 1) //寄存器地址超出范围
	{
		return -3;
	}

    if (pReq->usRegNum * 2 > 255) //超出范围
	{
		return -4;
	}

	// Head
    int iLenVal = 0;
	memset(pDataBuf, 0, SNED_BUFFER_LENGHT);

	// some variables  
	// 计算字节数
	quint16 usTemp = 0;

	addParam2Buffer(pDataBuf, pReq->usEvent);
    iLenVal += 2; //事务标识

	addParam2Buffer(pDataBuf + iLenVal, pReq->usProto);
    iLenVal += 2; //协议标识

    usTemp = pReq->usRegNum * 2 + 3; //长度,3=1单元标识/Modbus地址+1功能码+1字节数
	addParam2Buffer(pDataBuf + iLenVal, usTemp);
	iLenVal += 2;

	*(pDataBuf + iLenVal) = pReq->uaAddr;
	iLenVal += 1;

	*(pDataBuf + iLenVal) = pReq->uaFuncCode;
	iLenVal += 1;

    *(pDataBuf + iLenVal) = (char)(pReq->usRegNum * 2); //字节数
	iLenVal += 1;

	// data	
    for (quint16 usIndex = 0; usIndex < pReq->usRegNum; ++usIndex) //寄存器
	{
		if (pReq->usRegAddr - 1 + usIndex < 100)
		{
			usTemp = *(pComInputRegData + pReq->usRegAddr - 1 + usIndex);
		}
		else
		{
			usTemp = 0;
		}

		addParam2Buffer(pDataBuf + iLenVal, usTemp);
		iLenVal += 2;
	}

	return iLenVal;
}

// 返回处理的寄存器个数(处理8个寄存器)
// 返回 8 的倍数
void CModbusFactory::addRegVal2BufferBankDis(char* pData, quint16 usRegAddr, CBattBank* pBattBank)
{
    if (0 == pData || 0 == pBattBank)
	{
        return; //跳过该寄存器
	}

	uchar uaVal = 0;

	for (quint16 usIndex = 0; usIndex < 8; ++usIndex)
	{
		if (getRegValBankDis(usRegAddr + usIndex, pBattBank) > 0)
		{
			uaVal = uaVal | 0x80;
		}

		// 移位
        if (usIndex < 7) //0 - 6
		{
			uaVal = uaVal >> 1;
		}
	}

	*pData = uaVal;
}

// -1 - Not find
// 0 - bool false
//  > 0 - bool true
//获取电池簇的相关变量的离散值
int CModbusFactory::getRegValBankDis(quint16 usRegAddr, CBattBank* pBattBank)
{
    if (0 == pBattBank)
	{
		return -1;
	}

	// some variables
	int iRetVal = -1;

    if (usRegAddr >= 1 && usRegAddr <= 1400)
	{
		if (1 == usRegAddr)
		{
            iRetVal = pBattBank->aBankVolUpLimitWarn; //簇电压上限预警 1
		}
		else if (2 == usRegAddr)
		{
            iRetVal = pBattBank->aBankVolDownLimitWarn; //簇电压下限预警 2
		}
		else if (3 == usRegAddr)
		{
            iRetVal = pBattBank->aChgCurUpLimitWarn; //充电电流上限预警 3
		}
		else if (4 == usRegAddr)
		{
            iRetVal = pBattBank->aDchgCurUpLimitWarn; //放电电流上限预警 4
		}
		else if (5 == usRegAddr)
		{
            iRetVal = pBattBank->aSglVolUpLimitWarn; //单体电压上限预警 5
		}
		else if (6 == usRegAddr)
		{
            iRetVal = pBattBank->aSglVolDownLimitWarn; //单体电压下限预警 6
		}
		else if (7 == usRegAddr)
		{
            iRetVal = pBattBank->aChgTempUpLimitWarn; //充电温度上限预警 7
		}
		else if (8 == usRegAddr)
		{
            iRetVal = pBattBank->aChgTempDownLimitWarn; //充电温度下限预警 8
		}
		else if (9 == usRegAddr)
		{
            iRetVal = pBattBank->aDchgTempUpLimitWarn; //放电温度上限预警 9
		}
		else if (10 == usRegAddr)
		{
            iRetVal = pBattBank->aDchgTempDownLimitWarn; //放电温度下限预警 10
		}
		else if (11 == usRegAddr)
		{
            iRetVal = pBattBank->aSglTempUpLimitWarn; //单体温度上限预警 11
		}
		else if (12 == usRegAddr)
		{
            iRetVal = pBattBank->aSglTempDownLimitWarn; //单体温度下限预警 12
		}
		else if (13 == usRegAddr)
		{
            iRetVal = pBattBank->aEnvTempUpLimitWarn; //环境温度上限预警 13
		}
		else if (14 == usRegAddr)
		{
            iRetVal = pBattBank->aEnvTempDownLimitWarn; //环境温度下限预警 14
		}
		else if (15 == usRegAddr)
		{
            iRetVal = pBattBank->aPowerLineTempUpLimitWarn; //动力线温度上限预警 15
		}
		else if (16 == usRegAddr)
		{
            iRetVal = pBattBank->aBankSocUpLimitWarn; //SOC超上限预警 16
		}
		else if (17 == usRegAddr)
		{
            iRetVal = pBattBank->aBankSocDownLimitWarn; //SOC超下限预警 17
		}
		else if (18 == usRegAddr)
		{
            iRetVal = pBattBank->aPosResDownLimitWarn; //正极绝缘内阻下限预警 18
		}
		else if (19 == usRegAddr)
		{
            iRetVal = pBattBank->aNegResDownLimitWarn; //负极绝缘内阻下限预警 19
		}
		else if (20 == usRegAddr)
		{
            iRetVal = pBattBank->aPackVolDiffUpLimitWarn; //箱压差上限预警 20
		}
		else if (21 == usRegAddr)
		{
            iRetVal = pBattBank->aPackTempDiffUpLimitWarn; //箱温差上限预警 21
		}
		else if (22 == usRegAddr)
		{
            iRetVal = pBattBank->aBankVolUpLimitAlarm; //簇电压上限告警 23
		}
		else if (23 == usRegAddr)
		{
            iRetVal = pBattBank->aBankVolDownLimitAlarm; //簇电压下限告警 24
		}
		else if (24 == usRegAddr)
		{
            iRetVal = pBattBank->aChgCurUpLimitAlarm; //充电电流上限告警 25
		}
		else if (25 == usRegAddr)
		{
            iRetVal = pBattBank->aDchgCurUpLimitAlarm; //放电电流上限告警 26
		}
		else if (26 == usRegAddr)
		{
            iRetVal = pBattBank->aSglVolUpLimitAlarm; //单体电压上限告警 27
		}
		else if (27 == usRegAddr)
		{
            iRetVal = pBattBank->aSglVolDownLimitAlarm; //单体电压下限告警 28
		}
		else if (28 == usRegAddr)
		{
            iRetVal = pBattBank->aChgTempUpLimitAlarm; //充电温度上限告警 29
		}
		else if (29 == usRegAddr)
		{
            iRetVal = pBattBank->aChgTempDownLimitAlarm; //充电温度下限告警 30
		}
		else if (30 == usRegAddr)
		{
            iRetVal = pBattBank->aDchgTempUpLimitAlarm; //放电温度上限告警 31
		}
		else if (31 == usRegAddr)
		{
            iRetVal = pBattBank->aDchgTempDownLimitAlarm; //放电温度下限告警 32
		}
		else if (32 == usRegAddr)
		{
            iRetVal = pBattBank->aSglTempUpLimitAlarm; //单体温度上限告警 33
		}
		else if (33 == usRegAddr)
		{
            iRetVal = pBattBank->aSglTempDownLimitAlarm; //单体温度下限告警 34
		}
		else if (34 == usRegAddr)
		{
            iRetVal = pBattBank->aEnvTempUpLimitAlarm; //环境温度上限告警 35
		}
		else if (35 == usRegAddr)
		{
            iRetVal = pBattBank->aEnvTempDownLimitAlarm; //环境温度下限告警 36
		}
		else if (36 == usRegAddr)
		{
            iRetVal = pBattBank->aPowerLineTempUpLimitAlarm; //动力线温度上限告警 37
		}
		else if (37 == usRegAddr)
		{
            iRetVal = pBattBank->aBankSocUpLimitAlarm; //SOC超上限告警 38
		}
		else if (38 == usRegAddr)
		{
            iRetVal = pBattBank->aBankSocDownLimitAlarm; //SOC超下限告警 39
		}
		else if (39 == usRegAddr)
		{
            iRetVal = pBattBank->aPosResDownLimitAlarm; //正极绝缘内阻下限告警 40
		}
		else if (40 == usRegAddr)
		{
            iRetVal = pBattBank->aNegResDownLimitAlarm; //负极绝缘内阻下限告警 41
		}
		else if (41 == usRegAddr)
		{
            iRetVal = pBattBank->aPackVolDiffUpLimitAlarm; //箱压差上限告警 42
		}
		else if (42 == usRegAddr)
		{
            iRetVal = pBattBank->aPackTempDiffUpLimitAlarm; //箱温差上限告警 43
		}
		else if (43 == usRegAddr)
		{
            iRetVal = pBattBank->aBankVolUpLimitProt; //簇电压上限保护 45
		}
		else if (44 == usRegAddr)
		{
            iRetVal = pBattBank->aBankVolDownLimitProt; //簇电压下限保护 46
		}
		else if (45 == usRegAddr)
		{
            iRetVal = pBattBank->aChgCurUpLimitProt; //充电电流上限保护 47
		}
		else if (46 == usRegAddr)
		{
            iRetVal = pBattBank->aDchgCurUpLimitProt; //放电电流上限保护 48
		}
		else if (47 == usRegAddr)
		{
            iRetVal = pBattBank->aSglVolUpLimitProt; //单体电压上限保护 49
		}
		else if (48 == usRegAddr)
		{
            iRetVal = pBattBank->aSglVolDownLimitProt; //单体电压下限保护 50
		}
		else if (49 == usRegAddr)
		{
            iRetVal = pBattBank->aChgTempUpLimitProt; //充电温度上限保护 51
		}
		else if (50 == usRegAddr)
		{
            iRetVal = pBattBank->aChgTempDownLimitProt; //充电温度下限保护 52
		}
		else if (51 == usRegAddr)
		{
            iRetVal = pBattBank->aDchgTempUpLimitProt; //放电温度上限保护 53
		}
		else if (52 == usRegAddr)
		{
            iRetVal = pBattBank->aDchgTempDownLimitProt; //放电温度下限保护 54
		}
		else if (53 == usRegAddr)
		{
            iRetVal = pBattBank->aSglTempUpLimitProt; //单体温度上限保护 55
		}
		else if (54 == usRegAddr)
		{
            iRetVal = pBattBank->aSglTempDownLimitProt; //单体温度下限保护 56
		}
		else if (55 == usRegAddr)
		{
            iRetVal = pBattBank->aEnvTempUpLimitProt; //环境温度上限保护 57
		}
		else if (56 == usRegAddr)
		{
            iRetVal = pBattBank->aEnvTempDownLimitProt; //环境温度下限保护 58
		}
		else if (57 == usRegAddr)
		{
            iRetVal = pBattBank->aPowerLineTempUpLimitProt; //动力线温度上限保护 59
		}
		else if (58 == usRegAddr)
		{
            iRetVal = pBattBank->aBankSocUpLimitProt; //SOC超上限保护 60
		}
		else if (59 == usRegAddr)
		{
            iRetVal = pBattBank->aBankSocDownLimitProt; //SOC超下限保护 61
		}
		else if (60 == usRegAddr)
		{
            iRetVal = pBattBank->aPosResDownLimitProt; //正极绝缘内阻下限保护 62
		}
		else if (61 == usRegAddr)
		{
            iRetVal = pBattBank->aNegResDownLimitProt; //负极绝缘内阻下限保护 63
		}
		else if (62 == usRegAddr)
		{
            iRetVal = pBattBank->aPackVolDiffUpLimitProt; //箱压差上限保护 64
		}
		else if (63 == usRegAddr)
		{
            iRetVal = pBattBank->aPackTempDiffUpLimitProt; //箱温差上限保护 65
		}
		else if (64 == usRegAddr)
		{
            iRetVal = pBattBank->aSglTempRise; //电池温度温升过快 67
		}
		else if (65 == usRegAddr)
		{
            iRetVal = pBattBank->aPowerLineTempRise; //动力线温度温升过快 68
		}
		else if (66 == usRegAddr)
		{
            iRetVal = pBattBank->aBMUConnFault; //BMU通讯故障 69
		}
		else if (67 == usRegAddr)
		{
            iRetVal = pBattBank->aBCMUConnFault; //BCMU通讯故障 70
		}
		else if (68 == usRegAddr)
		{
            iRetVal = pBattBank->aSglVolWireFault; //单体电压采集线故障 71
		}
		else if (69 == usRegAddr)
		{
            iRetVal = pBattBank->aBankVolWireFault; //总压采集线故障 72
		}
		else if (70 == usRegAddr)
		{
            iRetVal = pBattBank->aCurWireFault; //电流采集线故障 73
		}
		else if (71 == usRegAddr)
		{
            iRetVal = pBattBank->aTempWireBreak; //温度采集断线 74
		}
		else if (72 == usRegAddr)
		{
            iRetVal = pBattBank->aTempShortCircuit; //温度采集短路 75
		}
		else if (73 == usRegAddr)
		{
            iRetVal = pBattBank->aBMSFault; //BMS设备故障  76
		}
		else if (74 == usRegAddr)
		{
            iRetVal = pBattBank->aSglVolInvalid; //单体电压无效 77
		}
		else if (75 == usRegAddr)
		{
            iRetVal = pBattBank->aSglTempInvalid; //单体温度无效 78
		}
		else if (76 == usRegAddr)
		{
            iRetVal = pBattBank->aBankVolInvalid; //簇端电压无效 79
		}
		else if (77 == usRegAddr)
		{
            iRetVal = pBattBank->aBankCurAbnormity; //簇电流异常 80
		}
		else if (78 == usRegAddr)
		{
            iRetVal = pBattBank->aPosJCQAdheFault; //总正接触器粘连故障 81
		}
		else if (79 == usRegAddr)
		{
            iRetVal = pBattBank->aNegJCQAdheFault; //总负接触器粘连故障 82
		}
		else if (80 == usRegAddr)
		{
            iRetVal = pBattBank->aPreJCQAdheFault; //预充接触器粘连故障 83
		}
		else if (81 == usRegAddr)
		{
            iRetVal = pBattBank->aPosJCQNotCloseFault; //总正接触器不闭合故障 84
		}
		else if (82 == usRegAddr)
		{
            iRetVal = pBattBank-> aNegJCQNotCloseFault; //总负接触器不闭合故障 85
		}
		else if (83 == usRegAddr)
		{
            iRetVal = pBattBank->aPreJCQNotCloseFault; //预充接触器不闭合故障 86
		}
		else if (84 == usRegAddr)
		{
            iRetVal = pBattBank->aHallComFault; //霍尔通讯故障 87
		}
		else if (85 == usRegAddr)
		{
            iRetVal = pBattBank->aHallDacFault; //霍尔采集故障 88
		}
		else if (86 == usRegAddr)
		{
            iRetVal = pBattBank->aPosFuseBreakFault; //正极熔断器断开故障
		}
		else if (87 == usRegAddr)
		{
            iRetVal = pBattBank->aNegFuseBreakFault; //负极熔断器断开故障
		}
		else if (88 == usRegAddr)
		{
            iRetVal = pBattBank->aBankVolDiffFault; //簇压采集差故障 87
		}
		else if (89 == usRegAddr)
		{
            iRetVal = pBattBank->aPackVolUpLimitWarn; //箱电压上限预警 89
		}
		else if (90 == usRegAddr)
		{
            iRetVal = pBattBank->aPackVolDownLimitWarn; //箱电压下限预警 90
		}
		else if (91 == usRegAddr)
		{
            iRetVal = pBattBank->aPackVolUpLimitAlarm; //箱电压上限告警 91
		}
		else if (92 == usRegAddr)
		{
            iRetVal = pBattBank->aPackVolDownLimitAlarm; //箱电压下限告警 92
		}
		else if (93 == usRegAddr)
		{
            iRetVal = pBattBank->aPackVolUpLimitProt; //箱电压上限保护 93
		}
		else if (94 == usRegAddr)
		{
            iRetVal = pBattBank->aPackVolDownLimitProt; //箱电压下限保护 94
		}
		else if (95 == usRegAddr)
		{
            iRetVal = pBattBank->aCellVolDiffUpLimitWarn; //簇内单体电压极差上限预警 95
		}
		else if (96 == usRegAddr)
		{
            iRetVal = pBattBank->aCellVolDiffUpLimitAlarm; //簇内单体电压极差上限告警 96
		}
		else if (97 == usRegAddr)
		{
            iRetVal = pBattBank->aCellVolDiffUpLimitProt; //簇内单体电压极差上限保护 97
		}
		else if (98 == usRegAddr)
		{
            iRetVal = pBattBank->aCellTempDiffUpLimitWarn; //簇内单体温度极差上限预警 98
		}
		else if (99 == usRegAddr)
		{
            iRetVal = pBattBank->aCellTempDiffUpLimitAlarm; //簇内单体温度极差上限告警 99
		}
		else if (100 == usRegAddr)
		{
            iRetVal = pBattBank->aCellTempDiffUpLimitProt; //簇内单体温度极差上限保护 100
		}
		else if (101 == usRegAddr)
		{
            iRetVal = pBattBank->aModuleVolDiffUpLimitWarn; //簇内模块电压极差上限预警 101
		}
		else if (102 == usRegAddr)
		{
            iRetVal = pBattBank->aModuleVolDiffUpLimitAlarm; //簇内模块电压极差上限告警 102
		}
		else if (103 == usRegAddr)
		{
            iRetVal = pBattBank->aModuleVolDiffUpLimitProt; //簇内模块电压极差上限保护 103
		}
		else if (104 == usRegAddr)
		{
            iRetVal = pBattBank->aHvPwLnTempUpLimitWarn; //高压动力线温度上限预警 104
		}
		else if (105 == usRegAddr)
		{
            iRetVal = pBattBank->aHvPwLnTempUpLimitAlarm; //高压动力线温度上限告警 105
		}
		else if (106 == usRegAddr)
		{
            iRetVal = pBattBank->aHvPwLnTempUpLimitProt; //高压动力线温度上限保护 106
		}
		else if (107 == usRegAddr)
		{
            iRetVal = pBattBank->aBankCurAbnormalWarn; //簇电流异常预警 107
		}
		else if (108 == usRegAddr)
		{
            iRetVal = pBattBank->aBankCurAbnormalAlarm; //簇电流异常告警 108
		}
		else if (109 == usRegAddr)
		{
            iRetVal = pBattBank->aBankCurAbnormalProt; //簇电流异常保护 109
		}
		else if (110 == usRegAddr)
		{
            iRetVal = pBattBank->aCellVolSudChgWarn; //电压突变预警  110
		}
		else if (111 == usRegAddr)
		{
            iRetVal = pBattBank->aCellVolSudChgAlarm; //电压突变告警  111
		}
		else if (112 == usRegAddr)
		{
            iRetVal = pBattBank->aCellVolSudChgProt; //电压突变保护  112
		}
		else if (113 == usRegAddr)
		{
            iRetVal = pBattBank->aCellInResAbnormal; //内阻异常报警  113
		}
		else if (114 == usRegAddr)
		{
            iRetVal = pBattBank->aPrechgFailed; //预充异常报警  114
		}
		else if (115 == usRegAddr)
		{
            iRetVal = pBattBank->aAlarmAvailable; //告警信息待获取 115
		}
        else if (usRegAddr >= 116 && usRegAddr <= 165) //216~165
		{
			iRetVal = pBattBank->aBankTemp[usRegAddr - 116]; 
		}
		else if (usRegAddr >= 201 && usRegAddr <= 800)
		{
            iRetVal = pBattBank->aChgEquState[usRegAddr - 201]; //充电均衡状态 201~800
		}
		else if (usRegAddr >= 801 && usRegAddr <= 1400)
		{
            iRetVal = pBattBank->aDchgEquState[usRegAddr - 801]; //放电均衡状态 801~1400
		}
		else
		{
			iRetVal = -1;
		}
	}
	else
	{
		iRetVal = -1;
	}

	return iRetVal;
}

// -1 - Not find
// 0 - bool false
//  > 0 - bool true
//获取电池堆的环境变量的离散值
int CModbusFactory::getRegValEnvDis(int iModbusAddress, quint16 usRegAddr, CBattStack* pBattStack)
{
    if (0 == pBattStack)
	{
		return -1;
	}

	// some variables
	int iRetVal = -1;
	int iIndex = 0;

	if (usRegAddr >= 1 && usRegAddr <= 40)
	{
        //空调1~空调20
		iIndex = (int)(usRegAddr / 2);
		if (1 == usRegAddr % 2)
		{
			if (iIndex >= 0 && iIndex < MAX_AC_NUM)
			{
                //空调通讯状态
				iRetVal = pBattStack->aACCommFault[iIndex];
			}
		}
		else
		{
			--iIndex;
			if (iIndex >= 0 && iIndex < MAX_AC_NUM)
			{
                //空调运行状态
				iRetVal = pBattStack->aACState[iIndex];
			}
		}
	}
	else if (usRegAddr >= 41 && usRegAddr <= 50)
	{
		iRetVal = pBattStack->aTHCommFault[usRegAddr - 41];
	}
	else if (usRegAddr >= 51 && usRegAddr <= 60)
	{
		iRetVal = pBattStack->aEnvWaterAlarm[usRegAddr - 51];
	}
	else if (usRegAddr >= 61 && usRegAddr < 111)
	{
		iRetVal = pBattStack->aEnvTemp[usRegAddr - 61];
	}
	else
	{
		iRetVal = -1;
	}

	return iRetVal;
}

// -1 - Not find
// 0 - bool false
//  > 0 - bool true
//获取电池堆的告警变量的离散值
int CModbusFactory::getRegValStackDis(quint16 usRegAddr, CBattStack* pBattStack)
{
	if (0 == pBattStack)
	{
		return -1;
	}

	// some variables
	int iRetVal = -1;

	if (1 == usRegAddr)
	{
        iRetVal = pBattStack->aEmerStop; //紧急停机
	}
	else if (2 == usRegAddr)
	{
        iRetVal = pBattStack->aFireWarn; //消防预警
	}
	else if (3 == usRegAddr)
	{
        iRetVal = pBattStack->aFireAction; //消防启动
	}
	else if (4 == usRegAddr)
	{
        iRetVal = pBattStack->aFireFault; //消防故障
	}
	else if (5 == usRegAddr)
	{
        iRetVal = pBattStack->aWaterAlarm; //水浸告警
	}
	else if (6 == usRegAddr)
	{
        iRetVal = pBattStack->aGasAlarm; //可燃气体
	}
	else if (7 == usRegAddr)
	{
        iRetVal = pBattStack->aAcceCtrlState; //门禁状态
	}
	else if (8 == usRegAddr)
	{
        iRetVal = pBattStack->aPCSCommFault; //PCS通讯故障
	}
	else if (9 == usRegAddr)
	{
        iRetVal = pBattStack->aEMSCommFault; //EMS通讯故障
	}
	else if (10 == usRegAddr)
	{
        iRetVal = pBattStack->aConfSwitchState; //汇流开关反馈
	}
	else if (11 == usRegAddr)
	{
        iRetVal = pBattStack->aExIOModuConnFault; //扩展IO模块通讯故障
	}
    else if (usRegAddr >= 12 && usRegAddr < 62)
	{
        //50个数簇值
        iRetVal = pBattStack->aStackTemp[usRegAddr - 12]; //aStackTemp
	}
	else
	{
		iRetVal = -1;
	}

	return iRetVal;
}

// 返回处理的寄存器个数
// 一个寄存器两个字节
quint16 CModbusFactory::addRegVal2BufferBank(char* pData, quint16 usRegAddr, CBattBank* pBattBank)
{
    if (0 == pData || 0 == pBattBank)
	{
        return 1; //跳过该寄存器
	}

	quint16 usRetVal = 1;
	quint16 usTemp = 0;
	quint32 uiTemp = 0;
	float fTemp = 0;

    //获取电池簇的相关变量的quint16/float/quint32值
	int iRetVal = getRegValBank(usRegAddr, pBattBank, usTemp, fTemp, uiTemp);
	if (1 == iRetVal)
	{
        //quint16值
		addParam2Buffer(pData, usTemp);
		usRetVal = 1;
	}
	else if (2 == iRetVal)
	{
        //float值
		addParam2Buffer(pData, fTemp);
		usRetVal = 2;
	}
	else if (3 == iRetVal)
	{
        //quint32值
		addParam2Buffer(pData, uiTemp);
		usRetVal = 2;
	}
	else
	{
		usRetVal = 1;
	}

    return usRetVal;
}

// -1 - Not find
// 2 - quint16 类型
// 2 - float 类型
// 3 - quint32
//获取电池簇的相关变量的quint16/float/quint32值
int CModbusFactory::getRegValBank(quint16 usRegAddr, CBattBank* pBattBank, quint16& usVal, float& fVal, quint32& uiVal)
{
    if (0 == pBattBank)
	{
		return -1;
	}

	// some variables
	int iRetVal = -1;

    if (usRegAddr >= 1 && usRegAddr <= 200) //1~200
	{
		if (1 == usRegAddr)
		{
            usVal = pBattBank->usBankState; //电池簇状态 1 0x1111充满,0x2222放空,0x5555待机,0xaaaa跳机,0xbbbb正常
			iRetVal = 1;
		}
		else if (2 == usRegAddr)
		{
            usVal = pBattBank->usBankChgDchgState; //电池簇充放电状态 2 2 - 开路 2 - 待机 3 - 充电 4 - 放电
			iRetVal = 1;
		}
		else if (3 == usRegAddr)
		{
            usVal = pBattBank->usCellNumInBank; //电池簇管辖电池节数 3
			iRetVal = 1;
		}
		else if (4 == usRegAddr)
		{
            usVal = pBattBank->usTempNumInBank; //电池簇管辖温度节数 4
			iRetVal = 1;
		}
		else if (5 == usRegAddr)
		{
            usVal = pBattBank->usPackNumInBank; //电池簇管辖PACK数 5
			iRetVal = 1;
		}
		else if (6 == usRegAddr)
		{
            usVal = pBattBank->usChgNum; //充电次数 6
			iRetVal = 1;
		}
		else if (7 == usRegAddr)
		{
            usVal = pBattBank->usDchgNum; //放电次数 7
			iRetVal = 1;
		}
		else if (8 == usRegAddr)
		{
            usVal = pBattBank->usSglMaxVolNo; //单体电压最大的单体编号 8
			iRetVal = 1;
		}
		else if (9 == usRegAddr)
		{
            usVal = pBattBank->usSglMinVolNo; //单体电压最小的单体编号 9
			iRetVal = 1;
		}
		else if (10 == usRegAddr)
		{
            usVal = pBattBank->usSglMaxTempNo; //单体温度最大的单体编号 10
			iRetVal = 1;
		}
		else if (11 == usRegAddr)
		{
            usVal = pBattBank->usSglMinTempNo; //单体温度最小的单体编号 11
			iRetVal = 1;
		}
		else if (12 == usRegAddr)
		{
            usVal = pBattBank->usSglMaxResNo; //单体内阻最大的单体编号 12
			iRetVal = 1;
		}
		else if (13 == usRegAddr)
		{
            usVal = pBattBank->usSglMinResNo; //单体内阻最小的单体编号 13
			iRetVal = 1;
		}
		else if (14 == usRegAddr)
		{
            usVal = pBattBank->usSglMaxSocNo; //单体SOC最大的单体编号  14
			iRetVal = 1;
		}
		else if (15 == usRegAddr)
		{
            usVal = pBattBank->usSglMinSocNo; //单体SOC最小的单体编号  15
			iRetVal = 1;
		}
		else if (16 == usRegAddr)
		{
            usVal = pBattBank->usSglMaxSohNo; //单体SOH最大的单体编号  16
			iRetVal = 1;
		}
		else if (17 == usRegAddr)
		{
            usVal = pBattBank->usSglMinSohNo; //单体SOH最小的单体编号  17
			iRetVal = 1;
		}
		else if (18 == usRegAddr)
		{
            usVal = pBattBank->usDI1; //开关量输入-DI1 18 2--闭合， 0--断开
			iRetVal = 1;
		}
		else if (19 == usRegAddr)
		{
            usVal = pBattBank->usDI2; //开关量输入-DI2 19
			iRetVal = 1;
		}
		else if (20 == usRegAddr)
		{
            usVal = pBattBank->usDI3; //开关量输入-DI3 20
			iRetVal = 1;
		}
		else if (21 == usRegAddr)
		{
            usVal = pBattBank->usDI4; //开关量输入-DI4 21
			iRetVal = 1;
		}

		else if (22 == usRegAddr)
		{
            usVal = pBattBank->usDI5; //开关量输入-DI5 22
			iRetVal = 1;
		}
		else if (23 == usRegAddr)
		{
            usVal = pBattBank->usDI6; //开关量输入-DI6 23
			iRetVal = 1;
		}
		else if (usRegAddr >= 24 && usRegAddr <= 50)
		{
			usVal = pBattBank->usBankTemp[usRegAddr - 24];
			iRetVal = 1;
		}
		
		else if (51 == usRegAddr)
		{
            fVal = pBattBank->fBankVol; //簇端电压 51
			iRetVal = 2;
		}
		else if (53 == usRegAddr)
		{
            fVal = pBattBank->fBankCur; //簇电流 53
			iRetVal = 2;
		}
		else if (55 == usRegAddr)
		{
            fVal = pBattBank->fBankSoc; //簇SOC 55
			iRetVal = 2;
		}
		else if (57 == usRegAddr)
		{
            fVal = pBattBank->fBankSoh; //簇SOH 57
			iRetVal = 2;
		}
		else if (59 == usRegAddr)
		{
            fVal = pBattBank->fEnvTemp; //环境温度 59
			iRetVal = 2;
		}
		else if (61 == usRegAddr)
		{
            fVal = pBattBank->fPosRes; //正极绝缘电阻 61
			iRetVal = 2;
		}
		else if (63 == usRegAddr)
		{
            fVal = pBattBank->fNegRes; //负极绝缘电阻 63
			iRetVal = 2;
		}
		else if (65 == usRegAddr)
		{
            fVal = pBattBank->fBankChargeEQ; //电池簇可充电量 65
			iRetVal = 2;
		}
		else if (67 == usRegAddr)
		{
            fVal = pBattBank->fBankDischargeEQ; //电池簇可放电量 67
			iRetVal = 2;
		}
		else if (69 == usRegAddr)
		{
            fVal = pBattBank->fBankSglChargeEQ; //电池簇单次充电电量 69
			iRetVal = 2;
		}
		else if (71 == usRegAddr)
		{
            fVal = pBattBank->fBankSglDischargeEQ; //电池簇单次放电电量 71
			iRetVal = 2;
		}
		else if (73 == usRegAddr)
		{
            fVal = (float)pBattBank->dblBankChargeEQAdd; //电池簇累计充电电量 73
			iRetVal = 2;
		}
		else if (75 == usRegAddr)
		{
            fVal = (float)pBattBank->dblBankDischargeEQAdd; //电池簇累计放电电量 75
			iRetVal = 2;
		}
		else if (77 == usRegAddr)
		{
            fVal = pBattBank->fSglVolDiffInBank; //簇单体电压压差极差值 77
			iRetVal = 2;
		}
		else if (79 == usRegAddr)
		{
            fVal = pBattBank->fSglAvgVol; //单体电压平均值 83
			iRetVal = 2;
		}
		else if (81 == usRegAddr)
		{
            fVal = pBattBank->fSglMaxVol; //单电电压最大值 85
			iRetVal = 2;
		}
		else if (83 == usRegAddr)
		{
            fVal = pBattBank->fSglMinVol; //单电电压最小值 87
			iRetVal = 2;
		}
		else if (85 == usRegAddr)
		{
            fVal = pBattBank->fSglTempDiffInBank; //簇单体温度温差极差值 85
			iRetVal = 2;
		}
		else if (87 == usRegAddr)
		{
            fVal = pBattBank->fSglAvgTemp; //单体温度平均值 89
			iRetVal = 2;
		}
		else if (89 == usRegAddr)
		{
            fVal = pBattBank->fSglMaxTemp; //单电温度最大值 91
			iRetVal = 2;
		}
		else if (91 == usRegAddr)
		{
            fVal = pBattBank->fSglMinTemp; //单电温度最小值 93
			iRetVal = 2;
		}
		else if (93 == usRegAddr)
		{
            fVal = pBattBank->fSglAvgRes; //单体平均内阻 95
			iRetVal = 2;
		}
		else if (95 == usRegAddr)
		{
            fVal = pBattBank->fSglMaxRes; //单体内阻最大值 97
			iRetVal = 2;
		}
		else if (97 == usRegAddr)
		{
            fVal = pBattBank->fSglMinRes; //单体内阻最小值 99
			iRetVal = 2;
		}
		else if (99 == usRegAddr)
		{
            fVal = pBattBank->fSglAvgSoc; //单体SOC平均值 101
			iRetVal = 2;
		}
		else if (101 == usRegAddr)
		{
            fVal = pBattBank->fSglMaxSoc; //单体SOC最大值 103
			iRetVal = 2;
		}
		else if (103 == usRegAddr)
		{
            fVal = pBattBank->fSglMinSoc; //单体SOC最小值 105
			iRetVal = 2;
		}
		else if (105 == usRegAddr)
		{
            fVal = pBattBank->fSglAvgSoh; //单体SOH平均值 107
			iRetVal = 2;
		}
		else if (107 == usRegAddr)
		{
            fVal = pBattBank->fSglMaxSoh; //单体SOH最大值 109
			iRetVal = 2;
		}
		else if (109 == usRegAddr)
		{
            fVal = pBattBank->fSglMinSoh; //单体SOH最小值 111
			iRetVal = 2;
		}
		else if (111 == usRegAddr)
		{
            fVal = pBattBank->fBankAllowMaxChargePower; //电池簇最大充电功率  113
			iRetVal = 2;
		}
		else if (113 == usRegAddr)
		{
            fVal = pBattBank->fBankAllowMaxDischargePower; //电池簇最大放电功率  115
			iRetVal = 2;
		}
		else if (115 == usRegAddr)
		{
            fVal = pBattBank->fBankAllowMaxChargeCurrent; //电池簇最大充电电流  117
			iRetVal = 2;
		}
		else if (117 == usRegAddr)
		{
            fVal = pBattBank->fBankAllowMaxDischargeCurrent; //电池簇最大放电电流  119
			iRetVal = 2;
		}
		else if (119 == usRegAddr)
		{
            fVal = pBattBank->fEnvTemp2; //环境温度 119
			iRetVal = 2;
		}
		else if (121 == usRegAddr)
		{
            fVal = pBattBank->fEnvTemp3; //环境温度 121
			iRetVal = 2;
		}
		else if (123 == usRegAddr)
		{
            fVal = pBattBank->fEnvTemp4; //环境温度 123
			iRetVal = 2;
		}
        else if (usRegAddr >= 125 && usRegAddr <= 200) //119 200
		{
			fVal = pBattBank->fBankTemp[(usRegAddr - 125) / 2]; 	      
			iRetVal = 2;
		}
	}
    else if (usRegAddr >= 201 && usRegAddr <= 1400) //单体电压 201 ~1400
	{
        if (1 == usRegAddr % 2) //正常的开始地址
		{
			fVal = pBattBank->fSglVol[((usRegAddr - 201) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}
	}

    else if (usRegAddr >= 1401 && usRegAddr <= 2600) //单体温度 1401~2600
	{
        if (1 == usRegAddr % 2) //正常的开始地址
		{
			fVal = pBattBank->fSglTemp[((usRegAddr - 1401) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}
	}

    else if (usRegAddr >= 2601 && usRegAddr <= 3800) //单体Soc 2601~3800
	{
        if (1 == usRegAddr % 2) //正常的开始地址
		{
			fVal = pBattBank->fSglSoc[((usRegAddr - 2601) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}
	}

    else if (usRegAddr >= 3801 && usRegAddr <= 5000) //单体内阻 3801~5000
	{
        if (1 == usRegAddr % 2) //正常的开始地址
		{
			fVal = pBattBank->fSglRes[((usRegAddr - 3801) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}
	}

    else if (usRegAddr >= 5001 && usRegAddr <= 6200) //单体Soh 5001~6200
	{
        if (1 == usRegAddr % 2) //正常的开始地址
		{
			fVal = pBattBank->fSglSoh[((usRegAddr - 5001) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}
	}

    else if (usRegAddr >= 6201 && usRegAddr <= 6400) //动力线温度 6201~6400
	{
        if (1 == usRegAddr % 2) //正常的开始地址
		{
			fVal = pBattBank->fPwLnTemp[((usRegAddr - 6201) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}
	}
    else if (usRegAddr >= 6401 && usRegAddr <= 6500) //动力线温度 6401~6500
	{
        if (1 == usRegAddr % 2) //正常的开始地址
		{
			fVal = pBattBank->fPackVol[((usRegAddr - 6401) / 2)];
			iRetVal = 2;
		}
		else
		{
			iRetVal = -1;
		}
	}
	else if (8001 == usRegAddr)
	{
        usVal = pBattBank->usBranState; //支路运行状态 8001 0x1111禁充 0x2222禁放 0x5555告警 0xAAAA故障 0xBBBB正常
		iRetVal = 1;
	}
	else if (8002 == usRegAddr)
	{
        usVal = pBattBank->usMaxBankSocNoInBran; //支路内簇SOC最高簇号 8002
		iRetVal = 1;
	}
	else if (8003 == usRegAddr)
	{
        usVal = pBattBank->usMinBankSocNoInBran; //支路内簇SOC最低簇号 8003
		iRetVal = 1;
	}
	else if (8004 == usRegAddr)
	{
        usVal = pBattBank->usMaxBankVolNoInBran; //支路内簇电压最高簇号 8004
		iRetVal = 1;
	}
	else if (8005 == usRegAddr)
	{
        usVal = pBattBank->usMinBankVolNoInBran; //支路内簇电压最低簇号 8005
		iRetVal = 1;
	}
	else if (8006 == usRegAddr)
	{
        usVal = pBattBank->usSglMaxVolBankNoInBran; //支路内最高单体电压电池簇号 8006
		iRetVal = 1;
	}
	else if (8007 == usRegAddr)
	{
        usVal = pBattBank->usSglMaxVolNoInBankInBran; //支路内最高单体电压所在簇的簇内编号 8007
		iRetVal = 1;
	}
	else if (8008 == usRegAddr)
	{
        usVal = pBattBank->usSglMinVolBankNoInBran; //支路内最低单体电压电池簇号 8008
		iRetVal = 1;
	}
	else if (8009 == usRegAddr)
	{
        usVal = pBattBank->usSglMinVolNoInBankInBran; //支路内最低单体电压所在簇的簇内编号 8009
		iRetVal = 1;
	}
	else if (8010 == usRegAddr)
	{
        usVal = pBattBank->usSglMaxTempBankNoInBran; //支路内最高单体温度电池簇号 8010
		iRetVal = 1;
	}
	else if (8011 == usRegAddr)
	{
        usVal = pBattBank->usSglMaxTempNoInBankInBran; //支路内最高单体温度所在簇的簇内编号 8011
		iRetVal = 1;
	}
	else if (8012 == usRegAddr)
	{
        usVal = pBattBank->usSglMinTempBankNoInBran; //支路内最低单体温度电池簇号 8012
		iRetVal = 1;
	}
	else if (8013 == usRegAddr)
	{
        usVal = pBattBank->usSglMinTempNoInBankInBran; //支路内最低单体温度所在簇的簇内编号 8013
		iRetVal = 1;
	}
	else if (usRegAddr >= 8014 && usRegAddr <= 8050)
	{
		usVal = pBattBank->usBranTemp[usRegAddr - 8014];
		iRetVal = 1;
	}
	
	else if (8051 == usRegAddr)
	{
        fVal = pBattBank->fBranVol; //支路电压 8051
		iRetVal = 2;
	}
	else if (8053 == usRegAddr)
	{
        fVal = pBattBank->fBranCur; //支路电流 8053
		iRetVal = 2;
	}
	else if (8055 == usRegAddr)
	{
        fVal = pBattBank->fBranSoc; //支路SOC 8055
		iRetVal = 2;
	}
	else if (8057 == usRegAddr)
	{
        fVal = pBattBank->fBranSoh; //支路SOH 8057
		iRetVal = 2;
	}
	else if (8059 == usRegAddr)
	{
        fVal = pBattBank->fBranChargeEQ; //支路可充电量 8059
		iRetVal = 2;
	}
	else if (8061 == usRegAddr)
	{
        fVal = pBattBank->fBranDischargeEQ; //支路可放电量 8061
		iRetVal = 2;
	}
	else if (8063 == usRegAddr)
	{
        fVal = pBattBank->fBranSglChargeEQ; //支路单次充电电量 8063
		iRetVal = 2;
	}
	else if (8065 == usRegAddr)
	{
        fVal = pBattBank->fBranSglDischargeEQ; //支路单次放电电量 8065
		iRetVal = 2;
	}
	else if (8067 == usRegAddr)
	{
        fVal = (float)pBattBank->dblBranChargeEQAdd; //支路充电量累加值 8067
		iRetVal = 2;
	}
	else if (8069 == usRegAddr)
	{
        fVal = (float)pBattBank->dblBranDischargeEQAdd; //支路放电量累加值 8069
		iRetVal = 2;
	}
	else if (8071 == usRegAddr)
	{
        fVal = pBattBank->fSglVolDiffInBran; //单体电压压差极差值 8071
		iRetVal = 2;
	}
	else if (8073 == usRegAddr)
	{
        fVal = pBattBank->fSglMaxVolInBran; //最高单体电压 8073
		iRetVal = 2;
	}
	else if (8075 == usRegAddr)
	{
        fVal = pBattBank->fSglMinVolInBran; //最低单体电压 8075
		iRetVal = 2;
	}
	else if (8077 == usRegAddr)
	{
        fVal = pBattBank->fSglTempDiffInBran; //电池温度温差极差值 8077
		iRetVal = 2;
	}
	else if (8079 == usRegAddr)
	{
        fVal = pBattBank->fSglMaxTempInBran; //最高电池温度 8079
		iRetVal = 2;
	}
	else if (8081 == usRegAddr)
	{
        fVal = pBattBank->fSglMinTempInBran; //最低电池温度 8081
		iRetVal = 2;
	}
	else if (8083 == usRegAddr)
	{
        fVal = pBattBank->fBankSocDiffInBran; //簇SOC差极差值 8083
		iRetVal = 2;
	}
	else if (8085 == usRegAddr)
	{
        fVal = pBattBank->fBankSocMaxInBran; //簇SOC最大 8085
		iRetVal = 2;
	}
	else if (8087 == usRegAddr)
	{
        fVal = pBattBank->fBankSocMinInBran; //簇SOC最小 8087
		iRetVal = 2;
	}
	else if (8089 == usRegAddr)
	{
        fVal = pBattBank->fBankVolDiffInBran; //簇电压差极差值 8089
		iRetVal = 2;
	}
	else if (8091 == usRegAddr)
	{
        fVal = pBattBank->fBankVolMaxInBran; //簇电压最大 8091
		iRetVal = 2;
	}
	else if (8093 == usRegAddr)
	{
        fVal = pBattBank->fBankVolMinInBran; //簇电压最小 8093
		iRetVal = 2;
	}
	else if (8095 == usRegAddr)
	{
        fVal = pBattBank->fBranAllowMaxChargePower; //支路当前允许最大充电功率 8095
		iRetVal = 2;
	}
	else if (8097 == usRegAddr)
	{
        fVal = pBattBank->fBranAllowMaxDischargePower; //支路当前允许最大放电功率 8097
		iRetVal = 2;
	}
	else if (8099 == usRegAddr)
	{
        fVal = pBattBank->fBranAllowMaxChargeCurrent; //支路当前允许最大充电电流 8099
		iRetVal = 2;
	}
	else if (8101 == usRegAddr)
	{
        fVal = pBattBank->fBranAllowMaxDischargeCurrent; //支路当前允许最大放电电流 8101
		iRetVal = 2;
	}
	else if (usRegAddr >= 8103 && usRegAddr <= 8200) //8103 - 8200  
	{
		fVal = pBattBank->fBranTemp[(usRegAddr - 8103) / 2]; 	      
		iRetVal = 2;
	}
	else
	{
		iRetVal = -1;
	}

	return iRetVal;
}

int CModbusFactory::setEnvAcValue(int iDevIndex, quint16 usRegAddr, quint16 usVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_AC_NUM)
    {
        return -1;
    }

    CAcData* pDev = 0;
    pDev = m_pRtdb->getAcDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    float fvalue = 0.0;
    if ((AC_REG_SET_MIN+0) == usRegAddr)
    {
        // 30001 RW 开关机 UINT16 1 0 0未知,1关机,2开机,默认为0
        pDev->m_uSetSwitchState = usVal;
        pDev->m_uSetSwitchStateCopy = usVal;
    }
    else if ((AC_REG_SET_MIN+1) == usRegAddr)
    {
        // 30002 RW 启动制冷命令 UINT16 1 0 0未知,1关闭,2启动,默认为0
        pDev->m_uSetStartCoolCmd = usVal;
        pDev->m_uSetStartCoolCmdCopy = usVal;
    }
    else if ((AC_REG_SET_MIN+2) == usRegAddr)
    {
        // 30003 RW 启动制热命令 UINT16 1 0 0未知,1关闭,2启动,默认为0
        pDev->m_uSetStartHotCmd = usVal;
        pDev->m_uSetStartHotCmdCopy = usVal;
    }
    else if ((AC_REG_SET_MIN+3) == usRegAddr)
    {
        // 30004 RW 启动待机命令 UINT16 1 0 0未知,1关闭,2启动,默认为0
        pDev->m_uSetStartWaitCmd = usVal;
        pDev->m_uSetStartWaitCmdCopy = usVal;
    }
    else if ((AC_REG_SET_MIN+4) == usRegAddr)
    {
        // 30005 RW 启动送风命令 UINT16 1 0 0未知,1关闭,2启动,默认为0
        pDev->m_uSetStartWindCmd = usVal;
        pDev->m_uSetStartWindCmdCopy = usVal;
    }
    else if ((AC_REG_SET_MIN+5) == usRegAddr)
    {
        // 30006 RW 启动除湿命令 UINT16 1 0 0未知,1关闭,2启动,默认为0
        pDev->m_uSetStartDryCmd = usVal;
        pDev->m_uSetStartDryCmdCopy = usVal;
    }
    else if ((AC_REG_SET_MIN+6) == usRegAddr)
    {
        // 30007 RW 下设的开启温度 UINT16 0.01 -100 ℃	"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetStartTemp = fvalue;
        pDev->m_fSetStartTempCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+7) == usRegAddr)
    {
        // 30008 RW 下设的停止温度 UINT16 0.01 -100 ℃
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetStopTemp = fvalue;
        pDev->m_fSetStopTempCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+8) == usRegAddr)
    {
        // 30009 RW 下设的制冷开始温度 UINT16 0.01 -100 ℃
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetCoolStartTemp = fvalue;
        pDev->m_fSetCoolStartTempCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+9) == usRegAddr)
    {
        // 30010 RW 下设的制冷停止温度 UINT16 0.01 -100 ℃
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetCoolStopTemp = fvalue;
        pDev->m_fSetCoolStopTempCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+10) == usRegAddr)
    {
        // 30011 RW 下设的制冷温度回差 UINT16 0.01 -100 ℃
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetCoolDiffTemp = fvalue;
        pDev->m_fSetCoolDiffTempCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+11) == usRegAddr)
    {
        // 30012 RW 下设的制热开始温度 UINT16 0.01 -100 ℃
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetHotStartTemp = fvalue;
        pDev->m_fSetHotStartTempCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+12) == usRegAddr)
    {
        // 30013 RW 下设的制热停止温度 UINT16 0.01 -100 ℃
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetHotStopTemp = fvalue;
        pDev->m_fSetHotStopTempCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+13) == usRegAddr)
    {
        // 30014 RW 下设的制热温度回差 UINT16 0.01 -100 ℃
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetHotDiffTemp = fvalue;
        pDev->m_fSetHotDiffTempCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+14) == usRegAddr)
    {
        // 30015 RW 下设的最高控制温度 UINT16 0.01 -100 ℃
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetCtrlTempMax = fvalue;
        pDev->m_fSetCtrlTempMaxCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+15) == usRegAddr)
    {
        // 30016 RW 下设的最低控制温度 UINT16 0.01 -100 ℃
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetCtrlTempMin = fvalue;
        pDev->m_fSetCtrlTempMinCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+16) == usRegAddr)
    {
        // 30017 RW 下设的平均控制温度 UINT16 0.01 -100 ℃
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetCtrlTempAvg = fvalue;
        pDev->m_fSetCtrlTempAvgCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+17) == usRegAddr)
    {
        // 30018 RW 下设的控制湿度 UINT16 0.01 -100 %
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetCtrlHumi = fvalue;
        pDev->m_fSetCtrlHumiCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+18) == usRegAddr)
    {
        // 30019 RW 下设的开始湿度 UINT16 0.01 -100 %
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetStartHumi = fvalue;
        pDev->m_fSetStartHumiCopy = fvalue;
    }
    else if ((AC_REG_SET_MIN+19) == usRegAddr)
    {
        // 30020 RW 下设的停止湿度 UINT16 0.01 -100 %
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetStopHumi = fvalue;
        pDev->m_fSetStopHumiCopy = fvalue;
    }
    else
    {
        // 30021~30200 预留
        iRetVal = -1;
    }

    return iRetVal;
}

// 写动环的保持寄存器-UINT16类型
// 0 - 正确处理
// -1 - 参数错误
// -2 - 地址错误
int CModbusFactory::setEnvLcValue(int iDevIndex, quint16 usRegAddr, quint16 usVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_LC_NUM)
    {
        return -1;
    }

    CLcData* pDev = 0;
    pDev = m_pRtdb->getLcDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    float fvalue = 0.0;

    if ((LC_REG_SET_MIN+0) == usRegAddr)
    {
        // 32401 W 控制模式 UINT16 1 0 0BMS控制 1自动控制 2强制控制
        pDev->m_uSetControlMode = usVal; //控制模式 0BMS控制 1自动控制 2强制控制
        pDev->m_uSetControlModeCopy = usVal;
    }
    else if ((LC_REG_SET_MIN+1) == usRegAddr)
    {
        // 32402 W 开关机 UINT16 1 0 0关机 1开机
        pDev->m_uSetMachineEnable = usVal; //开关机 0关机 1开机
        pDev->m_uSetMachineEnableCopy = usVal;
    }
    else if ((LC_REG_SET_MIN+2) == usRegAddr)
    {
        // 32403 W 工作状态 UINT16 1 0 0待机 1制冷 2制热 3循环 4自动
        pDev->m_uSetWorkState = usVal; //工作模式 0待机 1制冷 2制热 3循环 4自动
        pDev->m_uSetWorkStateCopy = usVal;
    }
    else if ((LC_REG_SET_MIN+3) == usRegAddr)
    {
        // 32404 W 下设目标温度 UINT16 0.01 -100 ℃
        // "实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetTargetTemp = fvalue;
        pDev->m_fSetTargetTempCopy = fvalue;
    }
    else if ((LC_REG_SET_MIN+4) == usRegAddr)
    {
        // 32402 W 下设的制冷开启温度 UINT16 0.01 -100 ℃
        //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetCoolStartTemp = fvalue;
        pDev->m_fSetCoolStartTempCopy = fvalue;
    }
    else if ((LC_REG_SET_MIN+5) == usRegAddr)
    {
        // 32406 W 下设的制冷停止温度 UINT16 0.01 -100 ℃
        //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetCoolStopTemp = fvalue;
        pDev->m_fSetCoolStopTempCopy = fvalue;
    }
    else if ((LC_REG_SET_MIN+6) == usRegAddr)
    {
        // 32407 W 下设的制冷回差温度 UINT16 0.01 -100 ℃
        //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetCoolDiffTemp = fvalue;
        pDev->m_fSetCoolDiffTempCopy = fvalue;
    }
    else if ((LC_REG_SET_MIN+7) == usRegAddr)
    {
        // 32408 W 下设的制热开启温度 UINT16 0.01 -100 ℃
        //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetHeatStartTemp = fvalue;
        pDev->m_fSetHeatStartTempCopy = fvalue;
    }
    else if ((LC_REG_SET_MIN+8) == usRegAddr)
    {
        // 32409 W 下设的制热停止温度 UINT16 0.01 -100 ℃
        //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetHeatStopTemp = fvalue;
        pDev->m_fSetHeatStopTempCopy = fvalue;
    }
    else if ((LC_REG_SET_MIN+9) == usRegAddr)
    {
        // 32410 W 下设的制热回差温度 UINT16 0.01 -100 ℃
        //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetHeatDiffTemp = fvalue;
        pDev->m_fSetHeatDiffTempCopy = fvalue;
    }
    else if ((LC_REG_SET_MIN+10) == usRegAddr)
    {
        // 32411 W 下设的除湿开启湿度 UINT16 0.01 -100 %
        //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetDryStartHumi = fvalue;
        pDev->m_fSetDryStartHumiCopy = fvalue;
    }
    else if ((LC_REG_SET_MIN+11) == usRegAddr)
    {
        // 32412 W 下设的除湿停止湿度 UINT16 0.01 -100 %
        //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetDryStopHumi = fvalue;
        pDev->m_fSetDryStopHumiCopy = fvalue;
    }
    else if ((LC_REG_SET_MIN+12) == usRegAddr)
    {
        // 32413 W 下设的除湿回差湿度 UINT16 0.01 -100 %
        //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
        fvalue = (float) ((float)usVal*0.01-100.0);
        pDev->m_fSetDryDiffHumi = fvalue;
        pDev->m_fSetDryDiffHumiCopy = fvalue;
    }
    else
    {
        //32414~32600 预留
        iRetVal = -1;
    }

    return iRetVal;
}

int CModbusFactory::setEnvPcsValue(int iDevIndex, quint16 usRegAddr, quint16 usVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_PCS_NUM)
    {
        return -1;
    }

    CPcsData* pDev = 0;
    pDev = m_pRtdb->getPcs(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    float fvalue = 0.0;
    if ((PCS_REG_SET_MIN+0) == usRegAddr)
    {
        // 33001 W 设置开关机 UINT16 1 0 0无动作,1关机,2开机,默认为0
        pDev->m_uSetSwitchState = usVal;
        pDev->m_uSetSwitchStateCopy = usVal;
    }
    else if ((PCS_REG_SET_MIN+1) == usRegAddr)
    {
        // 33002 W 设置控制模式 UINT16 1 0 "1-就地手动;2-就地曲线;3-就地电流;4-远程曲线(云平台);5-就地自动;6:就地自定义;7:第三方远程(其他ems)。"
        pDev->m_uSetRunMode = usVal;
        pDev->m_uSetRunModeCopy = usVal;
    }
    else if ((PCS_REG_SET_MIN+2) == usRegAddr)
    {
        // 33003 W 设置并离网 UINT16 1 0 0离网,1并网,2稳压
        pDev->m_uSetOnOffGridState = usVal;
        pDev->m_uSetOnOffGridStateCopy = usVal;
    }
    else if ((PCS_REG_SET_MIN+3) == usRegAddr)
    {
        // 33004 W 设置充电的有功功率 UINT16 0.1 0 kW "默认为0，实际值范围：0~6553.5kw"
        fvalue = 0.0;
        if (usVal > 0)
        {
            fvalue = (float)usVal * 0.1;
        }
        pDev->m_fSetActPower = fvalue;
        pDev->m_fSetActPowerCopy = fvalue;
    }
    else if ((PCS_REG_SET_MIN+4) == usRegAddr)
    {
        // 33005 W 设置放电的有功功率 UINT16 0.1 0 kW "默认为0，实际值范围：0~6553.5kw"
        fvalue = 0.0;
        if (usVal > 0)
        {
            fvalue = (float)usVal * 0.1;
            fvalue = -qFabs(fvalue);
        }
        pDev->m_fSetActPower = fvalue;
        pDev->m_fSetActPowerCopy = fvalue;
    }
    else if ((PCS_REG_SET_MIN+5) == usRegAddr)
    {
        // 33006 W 设置充电的无功功率 UINT16 0.1 0 kvar "默认为0,实际值范围：0~6553.5kvar"
        fvalue = 0.0;
        if (usVal > 0)
        {
            fvalue = (float)usVal * 0.1;
        }
        pDev->m_fSetReactPower = fvalue;
        pDev->m_fSetReactPowerCopy = fvalue;
    }
    else if ((PCS_REG_SET_MIN+6) == usRegAddr)
    {
        // 33007 W 设置放电的无功功率 UINT16 0.1 0 kvar "默认为0，实际值范围：0~6553.5kvar"
        fvalue = 0.0;
        if (usVal > 0)
        {
            fvalue = (float)usVal * 0.1;
            fvalue = -qFabs(fvalue);
        }
        pDev->m_fSetReactPower = fvalue;
        pDev->m_fSetReactPowerCopy = fvalue;
    }
    else if ((PCS_REG_SET_MIN+7) == usRegAddr)
    {
        // 33008 W 设置故障复位 UINT16 1 0 0不动作,1故障复位，默认为0
        pDev->m_uSetFaultReset = usVal;
        pDev->m_uSetFaultResetCopy = usVal;
    }
    else
    {
        // 33009~33200 预留
        iRetVal = -1;
    }

    return iRetVal;
}

// 保持寄存器 - UINT16 类型
// 0 - 正确处理
// -1 - 参数错误
// -2 - 地址错误
int CModbusFactory::setAlarmHoldRegVal(quint16 usRegAddr, quint16 usVal, SAlarmParam* pAlarmParam, CBattBank* pBattBank, CBattStack* pBattStack)
{
    if (0 == pAlarmParam || 0 == pBattBank || 0 == pBattStack)
	{
		return -1;
	}

	int iRetVal = -999;
	float fTemp = 0;

	if (1 == usRegAddr)
	{
		if (1 == pBattStack->usRunMode)
		{
			if (0 == usVal || 1 == usVal || 2 == usVal)
			{
				if (pBattBank->usEMSContCtrlPos != usVal)
				{
					pBattBank->usEMSContCtrlPos = usVal;
					pBattBank->usEMSContModifyCountPos = 1;
				}

				iRetVal = 0;
			}
			else
			{
				iRetVal = -1;
			}
		}
		else
		{
			iRetVal = -1;
		}
	}
	else if (2 == usRegAddr)
	{
		if (1 == pBattStack->usRunMode)
		{
			if (0 == usVal || 1 == usVal || 2 == usVal)
			{
				if (pBattBank->usEMSContCtrlNeg != usVal)
				{
					pBattBank->usEMSContCtrlNeg = usVal;
					pBattBank->usEMSContModifyCountNeg = 1;
				}

				iRetVal = 0;
			}
			else
			{
				iRetVal = -1;
			}
		}
		else
		{
			iRetVal = -1;
		}
	}

    else if (3 == usRegAddr) //簇端电压预警上限值 1
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (4 == usRegAddr) //簇端电压预警下限值	 2
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitWarn = fTemp;
            pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (5 == usRegAddr) //充电电流预警上限值 3
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitWarn = fTemp;
            pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (6 == usRegAddr) //放电电流预警上限值 4
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitWarn = fTemp;
            pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (7 == usRegAddr) //单体电压预警上限值 5
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (8 == usRegAddr) //单体电压预警下限值 6
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (9 == usRegAddr) //簇SOC预警上限值 7
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fBankSocUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (10 == usRegAddr) //簇SOC预警下限值 8
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fBankSocDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (11 == usRegAddr) //环境温度预警上限值 9
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fEnvTempUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (12 == usRegAddr) //环境温度预警下限值 10
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fEnvTempDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (13 == usRegAddr) //动力线温度预警上限值 11
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPowerLineTempUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fPowerLineTempUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (14 == usRegAddr) //充电温度预警上限值 12
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (15 == usRegAddr) //充电温度预警下限值 13
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (16 == usRegAddr) //放电温度预警上限值 14
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (17 == usRegAddr) //放电温度预警下限值 15
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (18 == usRegAddr) //单体温度预警上限值 16
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fSglTempUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (19 == usRegAddr) //单体温度预警下限值 17
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fSglTempDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (20 == usRegAddr) //正极绝缘电阻预警下限值 18
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (21 == usRegAddr) //负极绝缘电阻预警下限值 19
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitWarn) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (22 == usRegAddr) //箱压差上限预警 20
	{
		fTemp = usVal;
		if (qAbs(fTemp - pAlarmParam->fPackVolDiffUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fPackVolDiffUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (23 == usRegAddr) //箱温差上限预警 21
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPackTempDiffUpLimitWarn) > 0.0001)
		{
			pAlarmParam->fPackTempDiffUpLimitWarn = fTemp;
			pBattBank->usWarnParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (24 == usRegAddr) //簇端电压告警上限值 22
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (25 == usRegAddr) //簇端电压告警下限值	 23
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitAlarm = fTemp;
            pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (26 == usRegAddr) //充电电流告警上限值	 24
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitAlarm = fTemp;
            pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (27 == usRegAddr) //放电电流告警上限值 25
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitAlarm = fTemp;
            pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (28 == usRegAddr) //单体电压告警上限值 26
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (29 == usRegAddr) //单体电压告警下限值 27
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (30 == usRegAddr) //簇SOC告警上限值 28
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fBankSocUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (31 == usRegAddr) //簇SOC告警下限值 29
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fBankSocDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (32 == usRegAddr) //环境温度告警上限值 30
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fEnvTempUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (33 == usRegAddr) //环境温度告警下限值 31
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fEnvTempDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (34 == usRegAddr) //动力线温度告警上限值 32
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPowerLineTempUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fPowerLineTempUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (35 == usRegAddr) //充电温度告警上限值 33
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (36 == usRegAddr) //充电温度告警下限值 34
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (37 == usRegAddr) //放电温度告警上限值 35
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (38 == usRegAddr) //放电温度告警下限值 36
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (39 == usRegAddr) //单体温度告警上限值 37
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fSglTempUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (40 == usRegAddr) //单体温度告警下限值 38
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fSglTempDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (41 == usRegAddr) //正极绝缘电阻告警下限值 39
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (42 == usRegAddr) //负极绝缘电阻告警下限值 40
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitAlarm) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (43 == usRegAddr) //箱压差上限告警 41
	{
		fTemp = usVal;
		if (qAbs(fTemp - pAlarmParam->fPackVolDiffUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fPackVolDiffUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (44 == usRegAddr) //箱温差上限告警 42
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPackTempDiffUpLimitAlarm) > 0.0001)
		{
			pAlarmParam->fPackTempDiffUpLimitAlarm = fTemp;
			pBattBank->usAlarmParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (45 == usRegAddr) //簇端电压保护上限值 43
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitProt) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (46 == usRegAddr) //簇端电压保护下限值 44
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitProt) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitProt = fTemp;
            pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (47 == usRegAddr) //充电电流保护上限值 45
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitProt) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitProt = fTemp;
            pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (48 == usRegAddr) //放电电流保护上限值 46
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitProt) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitProt = fTemp;
            pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (49 == usRegAddr) //单体电压保护上限值 47
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitProt) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (50 == usRegAddr) //单体电压保护下限值 48
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitProt) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (51 == usRegAddr) //簇SOC保护上限值 49
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocUpLimitProt) > 0.0001)
		{
			pAlarmParam->fBankSocUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (52 == usRegAddr) //簇SOC保护下限值 50
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocDownLimitProt) > 0.0001)
		{
			pAlarmParam->fBankSocDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (53 == usRegAddr) //环境温度保护上限值 51
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempUpLimitProt) > 0.0001)
		{
			pAlarmParam->fEnvTempUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (54 == usRegAddr) //环境温度保护下限值 52
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempDownLimitProt) > 0.0001)
		{
			pAlarmParam->fEnvTempDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (55 == usRegAddr) //动力线温度保护上限值 53
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPowerLineTempUpLimitProt) > 0.0001)
		{
			pAlarmParam->fPowerLineTempUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (56 == usRegAddr) //充电温度保护上限值 54
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitProt) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (57 == usRegAddr) //充电温度保护下限值 55
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitProt) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (58 == usRegAddr) //放电温度保护上限值 56
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitProt) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (59 == usRegAddr) //放电温度保护下限值 57
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitProt) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (60 == usRegAddr) //单体温度保护上限值 58
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempUpLimitProt) > 0.0001)
		{
			pAlarmParam->fSglTempUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (61 == usRegAddr) //单体温度保护下限值 59
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempDownLimitProt) > 0.0001)
		{
			pAlarmParam->fSglTempDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (62 == usRegAddr) //正极绝缘电阻保护下限值 60
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitProt) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (63 == usRegAddr) //负极绝缘电阻保护下限值 61
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitProt) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (64 == usRegAddr) //箱压差上限保护 62
	{
		fTemp = usVal;
		if (qAbs(fTemp - pAlarmParam->fPackVolDiffUpLimitProt) > 0.0001)
		{
			pAlarmParam->fPackVolDiffUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (65 == usRegAddr) //箱温差上限保护 63
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPackTempDiffUpLimitProt) > 0.0001)
		{
			pAlarmParam->fPackTempDiffUpLimitProt = fTemp;
			pBattBank->usProtParamModifyCount= 1;
		}
		iRetVal = 0;
	}
    else if (66 == usRegAddr) //簇端电压预警回差上限值  1
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (67 == usRegAddr) //簇端电压预警回差下限值	 2
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitWarnHC = fTemp;
            pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (68 == usRegAddr) //充电电流预警回差上限值 3
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitWarnHC = fTemp;
            pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (69 == usRegAddr) //放电电流预警回差上限值 4
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitWarnHC = fTemp;
            pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (70 == usRegAddr) //单体电压预警回差上限值 5
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (71 == usRegAddr) //单体电压预警回差下限值 6
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (72 == usRegAddr) //簇SOC预警回差上限值 7
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fBankSocUpLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (73 == usRegAddr) //簇SOC预警回差下限值 8
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fBankSocDownLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (74 == usRegAddr) //环境温度预警回差上限值 9
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fEnvTempUpLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (75 == usRegAddr) //环境温度预警回差下限值 10
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fEnvTempDownLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (76 == usRegAddr) //动力线温度预警回差上限值 11
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPowerLineTempUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fPowerLineTempUpLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (77 == usRegAddr) //充电温度预警回差上限值 12
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (78 == usRegAddr) //充电温度预警回差下限值 13
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (79 == usRegAddr) //放电温度预警回差上限值 14
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (80 == usRegAddr) //放电温度预警回差下限值 15
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (81 == usRegAddr) //单体温度预警回差上限值 16
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fSglTempUpLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (82 == usRegAddr) //单体温度预警回差下限值 17
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fSglTempDownLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (83 == usRegAddr) //正极绝缘电阻预警回差下限值 18
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (84 == usRegAddr) //负极绝缘电阻预警回差下限值 19
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (85 == usRegAddr) //箱压差上限预警回差 20
	{
		fTemp = usVal;
		if (qAbs(fTemp - pAlarmParam->fPackVolDiffUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fPackVolDiffUpLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (86 == usRegAddr) //箱温差上限预警回差 21
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPackTempDiffUpLimitWarnHC) > 0.0001)
		{
			pAlarmParam->fPackTempDiffUpLimitWarnHC = fTemp;
			pBattBank->usWarnHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (87 == usRegAddr) //簇端电压告警回差上限值 2
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (88 == usRegAddr) //簇端电压告警回差下限值	 2
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitAlarmHC = fTemp;
            pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (89 == usRegAddr) //充电电流告警回差上限值 3
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitAlarmHC = fTemp;
            pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (90 == usRegAddr) //放电电流告警回差上限值 4
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitAlarmHC = fTemp;
            pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (91 == usRegAddr) //单体电压告警回差上限值 5
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (92 == usRegAddr) //单体电压告警回差下限值 6
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (93 == usRegAddr) //簇SOC告警回差上限值 7
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fBankSocUpLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (94 == usRegAddr) //簇SOC告警回差下限值 8
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fBankSocDownLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (95 == usRegAddr) //环境温度告警回差上限值 9
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fEnvTempUpLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (96 == usRegAddr) //环境温度告警回差下限值 20
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fEnvTempDownLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (97 == usRegAddr) //动力线温度告警回差上限值 21
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPowerLineTempUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fPowerLineTempUpLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (98 == usRegAddr) //充电温度告警回差上限值 22
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (99 == usRegAddr) //充电温度告警回差下限值 23
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (100 == usRegAddr) //放电温度告警回差上限值 24
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (101 == usRegAddr) //放电温度告警回差下限值 25
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (102 == usRegAddr) //单体温度告警回差上限值 26
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fSglTempUpLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (103 == usRegAddr) //单体温度告警回差下限值 27
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fSglTempDownLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (104 == usRegAddr) //正极绝缘电阻告警回差下限值 28
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (105 == usRegAddr) //负极绝缘电阻告警回差下限值 29
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (106 == usRegAddr) //箱压差上限告警回差 20
	{
		fTemp = usVal;
		if (qAbs(fTemp - pAlarmParam->fPackVolDiffUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fPackVolDiffUpLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (107 == usRegAddr) //箱温差上限告警回差 21
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPackTempDiffUpLimitAlarmHC) > 0.0001)
		{
			pAlarmParam->fPackTempDiffUpLimitAlarmHC = fTemp;
			pBattBank->usAlarmHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (108 == usRegAddr) //簇端电压保护回差上限值 2
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fBankVolUpLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (109 == usRegAddr) //簇端电压保护回差下限值	 2
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankVolDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fBankVolDownLimitProtHC = fTemp;
            pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (110 == usRegAddr) //充电电流保护回差上限值 3
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeCurUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fChargeCurUpLimitProtHC = fTemp;
            pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (111 == usRegAddr) //放电电流保护回差上限值 4
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDischargeCurUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fDischargeCurUpLimitProtHC = fTemp;
            pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (112 == usRegAddr) //单体电压保护回差上限值 5
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fSglVolUpLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (113 == usRegAddr) //单体电压保护回差下限值 6
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fSglVolDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fSglVolDownLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (114 == usRegAddr) //簇SOC保护回差上限值 7
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fBankSocUpLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (115 == usRegAddr) //簇SOC保护回差下限值 8
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fBankSocDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fBankSocDownLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (116 == usRegAddr) //环境温度保护回差上限值 9
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fEnvTempUpLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (117 == usRegAddr) //环境温度保护回差下限值 20
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fEnvTempDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fEnvTempDownLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (118 == usRegAddr) //动力线温度保护回差上限值 21
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPowerLineTempUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fPowerLineTempUpLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (119 == usRegAddr) //充电温度保护回差上限值 22
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempUpLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (120 == usRegAddr) //充电温度保护回差下限值 23
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fChargeSglTempDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fChargeSglTempDownLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (121 == usRegAddr) //放电温度保护回差上限值 24
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempUpLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
#ifdef XNWIN
    if (122 == usRegAddr) //放电温度保护回差下限值 25
#else
    else if (122 == usRegAddr) //放电温度保护回差下限值 25
#endif
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fDchargeSglTempDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fDchargeSglTempDownLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (123 == usRegAddr) //单体温度保护回差上限值 26
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fSglTempUpLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (124 == usRegAddr) //单体温度保护回差下限值 27
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fSglTempDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fSglTempDownLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (125 == usRegAddr) //正极绝缘电阻保护回差下限值 28
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fPosResDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fPosResDownLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (126 == usRegAddr) //负极绝缘电阻保护回差下限值 29
	{
		fTemp = usVal * 0.001;
		if (qAbs(fTemp - pAlarmParam->fNegResDownLimitProtHC) > 0.0001)
		{
			pAlarmParam->fNegResDownLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (127 == usRegAddr) //箱压差上限保护回差 20
	{
		fTemp = usVal;
		if (qAbs(fTemp - pAlarmParam->fPackVolDiffUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fPackVolDiffUpLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
	}
    else if (128 == usRegAddr) //箱温差上限保护回差 21
	{
		fTemp = usVal * 0.1;
		if (qAbs(fTemp - pAlarmParam->fPackTempDiffUpLimitProtHC) > 0.0001)
		{
			pAlarmParam->fPackTempDiffUpLimitProtHC = fTemp;
			pBattBank->usProtHCParamModifyCount = 1;
		}
		iRetVal = 0;
    }
    else if (usRegAddr >= 129 && usRegAddr <= 178) //usBankHoldTemp 229 - 178
	{
		if (pBattBank->usBankHoldTemp[usRegAddr - 129] != usVal)
		{
			pBattBank->usBankHoldTemp[usRegAddr - 129] = usVal;
			pBattBank->usBankTempParamModifyCount = 1;
		}

		iRetVal = 0;
	}

    else if (200 == usRegAddr) //簇端电压调整步长(系数) 37
	{ 	  
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fBankVolCoe) > 0.0001)
		{
			pBattBank->fBankVolCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
				
		iRetVal = 0;
	}
    else if (201 == usRegAddr) //充电电流调整步长(系数) 38
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fChargeCurCoe) > 0.0001)
		{
			pBattBank->fChargeCurCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
    else if (202 == usRegAddr) //放电电流调整步长(系数) 39
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fDischargeCurCoe) > 0.0001)
		{
			pBattBank->fDischargeCurCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
    else if (203 == usRegAddr) //环境温度调整步长(系数) 40
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fEnvTempCoe) > 0.0001)
		{
			pBattBank->fEnvTempCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
    else if (204 == usRegAddr) //单体电压调整步长(系数) 41
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fSglVolCoe) > 0.0001)
		{
			pBattBank->fSglVolCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
    else if (205 == usRegAddr) //单体温度调整步长(系数) 42
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fSglTempCoe) > 0.0001)
		{
			pBattBank->fSglTempCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
    else if (206 == usRegAddr) //SOC标定基准上限值调整步长(系数) 43
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fBankSocRefUpLmtCoe) > 0.0001)
		{
			pBattBank->fBankSocRefUpLmtCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
    else if (207 == usRegAddr) //SOC标定基准下限值调整步长(系数) 44
	{
		fTemp = (usVal - 1000) * 0.1;
		if (qAbs(fTemp - pBattBank->fBankSocRefDownLmtCoe) > 0.0001)
		{
			pBattBank->fBankSocRefDownLmtCoe = fTemp;
			pBattBank->usMonitorParamModifyCount = 1;
		}
		
		iRetVal = 0;
	}
	
	else
	{
		iRetVal = -2;
	}

    return iRetVal;
}

// 保持寄存器 - UINT16 类型
// 0 - 正确处理
// -1 - 参数错误
// -2 - 地址错误
// -3 - 设置值失败
int CModbusFactory::setStackHoldRegVal(quint16 usRegAddr, quint16 usVal, CBattStack* pBattStack)
{
	if (0 == pBattStack)
	{
		return -1;
	}

	int iRetVal = -999;

    if (1 == usRegAddr) //接触器断开前延时时间 2
	{
		if (pBattStack->usDelayBeforeCutCntor != usVal)
		{
			pBattStack->usDelayBeforeCutCntor = usVal;
			pBattStack->usDlyBfCutCntorModifyCount = 1;
		}
		
		iRetVal = 0;
	}
    else if (2 == usRegAddr) //年 2
	{
		if (usVal > 2017 && usVal < 3018) //2018~3018
		{
			pBattStack->usYear = usVal;
			iRetVal = 0;
		}
		else
		{
			iRetVal = -3;
		}
	}
    else if (3 == usRegAddr) //月	      3
	{
        if (usVal >= 1 && usVal <= 12) //1~12
		{
			pBattStack->usMonth = usVal;
			iRetVal = 0;
		}
		else
		{
			iRetVal = -3;
		}
	}
    else if (4 == usRegAddr) //日 4
	{
        if (usVal >= 1 && usVal <= 31) //1~31
		{
			pBattStack->usDay = usVal;
            iRetVal = 0;
		}
		else
		{
			iRetVal = -3;
		}
	}
    else if (5 == usRegAddr) //时 5
	{
        if (usVal >= 0 && usVal <= 23) //0~23
		{
			pBattStack->usHour = usVal;
            iRetVal = 0;
		}
		else
		{
			iRetVal = -3;
		}
	}
    else if (6 == usRegAddr) //分 6
	{
        if (usVal >= 0 && usVal <= 59) //0~59
		{
			pBattStack->usMin = usVal;
            iRetVal = 0;
		}
		else
		{
			iRetVal = -3;
		}
	}
    else if (7 == usRegAddr) //秒 7
	{
        if (usVal >= 0 && usVal <= 59) //0~59
		{
			pBattStack->usSec = usVal;
            iRetVal = 0;
		}
		else
		{
			iRetVal = -3;
		}
	}
    else if (8 == usRegAddr) //设置日期确认 8
	{
		iRetVal = -3;

		if (usVal > 0)
		{
            if (pBattStack->usYear > 2017 && pBattStack->usYear < 3018
                && pBattStack->usMonth >= 1 && pBattStack->usMonth <= 12
                && pBattStack->usDay >= 1 && pBattStack->usDay <= 31
                && pBattStack->usHour <= 23
                && pBattStack->usMin <= 59
                && pBattStack->usSec <= 59)
			{
                QDate dateNow = QDate(pBattStack->usYear, pBattStack->usMonth, pBattStack->usDay);
                QTime timeNow = QTime(pBattStack->usHour, pBattStack->usMin, pBattStack->usSec);
                CDatetimeUtil::SetLocalTime(QDateTime(dateNow, timeNow));
                iRetVal = 0;
			}
		}
	}
    else if (9 == usRegAddr) //堆接触器管理 9
	{
        if (1 == pBattStack->usRunMode) //2 - 远程
		{
			if (0 == usVal || 1 == usVal || 2 == usVal)
			{
				if (pBattStack->usEMSContCtrl != usVal)
				{
					pBattStack->usEMSContCtrl = usVal;
					pBattStack->usEMSContModifyCount = 1;
				}

				iRetVal = 0;
			}
			else
			{
				iRetVal = -1;
			}
		}
		else
		{
			iRetVal = -1;
		}
	}
    else if (10 == usRegAddr) //汇流开关管理 20
	{
        //if (1 == pBattStack->usRunMode) //2 - 远程
		{
			if (0 == usVal || 1 == usVal || 2 == usVal)
			{
				if (pBattStack->usEMSConfCtrl != usVal)
				{
					pBattStack->usEMSConfCtrl = usVal;
					pBattStack->usEMSConfModifyCount = 1;
				}

				iRetVal = 0;
			}
			else
			{
				iRetVal = -1;
			}
		}
		/*else
		{
			iRetVal = -1;
		}*/
	}
    else if (11 == usRegAddr) //故障清除 21
	{
        //if (1 == pBattStack->usRunMode) //2 - 远程
		{
			if (1 == usVal)
			{
				pBattStack->usEMSFaultClear = 1;
				pBattStack->usEMSFaultClearModifyCount = 1;
				
				iRetVal = 0;
			}
			else if (0 == usVal)
			{
				pBattStack->usEMSFaultClear = 0;
				iRetVal = 0;
			}
			else
			{
				iRetVal = -1;
			}
		}
		/*else
		{
			iRetVal = -1;
		}*/
	}
    else if (12 == usRegAddr) //FTP服务端IP1 22
	{
		pBattStack->usFtpIP1 = usVal;
		iRetVal = 0;
	}
    else if (13 == usRegAddr) //FTP服务端IP1 23
	{
		pBattStack->usFtpIP2 = usVal;
		iRetVal = 0;
	}
    else if (14 == usRegAddr) //FTP服务端IP1 24
	{
		pBattStack->usFtpIP3 = usVal;
		iRetVal = 0;
	}
    else if (15 == usRegAddr) //FTP服务端IP1 25
	{
		pBattStack->usFtpIP4 = usVal;
		iRetVal = 0;
	}
    else if (16 == usRegAddr) //EMS通知升级 26 0-无新升级包,1-FTP服务端中存在升级包
	{
		if (1 == usVal)
		{
            pBattStack->usEMSNotifyUpgrade = 1;
			pBattStack->usEMSNotifyUpgradeModifyCount = 1;
			
			iRetVal = 0;
		}
		else if (0 == usVal)
		{
			pBattStack->usEMSNotifyUpgrade = 0; 
			iRetVal = 0;
		}
		else
		{
			iRetVal = -1;
		}
	}
    else if (usRegAddr >= 30 && usRegAddr <= 79) //30 - 79
	{
		if (pBattStack->usStackHoldTemp[usRegAddr - 30] != usVal)
		{
			pBattStack->usStackHoldTemp[usRegAddr - 30] = usVal;
			pBattStack->usStackTempParamModifyCount = 1;
		}
		iRetVal = 0;
	}

	else
	{
		iRetVal = -2;
	}

    return iRetVal;
}

// 保持寄存器 - UINT16 类型
// 0 - 正确处理
// -1 - 错误
// -2 - 地址错误
int CModbusFactory::addHoldRegVal2BufferAlarm(char* pData, quint16 usRegAddr, SAlarmParam* pAlarmParam, CBattBank* pBattBank)
{
    if (0 == pData || 0 == pAlarmParam || 0 == pBattBank)
	{
		return -1;
	}

	int iRetVal = -999;
	quint16 usTemp = 0;

	if (1 == usRegAddr) 
	{
        usTemp = pBattBank->usEMSContCtrlPos;
		iRetVal = 0;
	}
	else if (2 == usRegAddr)
	{
        usTemp = pBattBank->usEMSContCtrlNeg;
		iRetVal = 0;
	}
    else if (3 == usRegAddr) //簇端电压预警上限值 3
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitWarn * 10);
		iRetVal = 0;
	}
    else if (4 == usRegAddr) //簇端电压预警下限值 4
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitWarn * 10);
		iRetVal = 0;
	}
    else if (5 == usRegAddr) //充电电流预警上限值 5
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitWarn * 10);
		iRetVal = 0;
	}
    else if (6 == usRegAddr) //放电电流预警上限值 6
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitWarn * 10);
		iRetVal = 0;
	}
    else if (7 == usRegAddr) //单体电压预警上限值 7
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitWarn * 1000);
		iRetVal = 0;
	}
    else if (8 == usRegAddr) //单体电压预警下限值 8
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitWarn * 1000);
		iRetVal = 0;
	}
    else if (9 == usRegAddr) //簇SOC预警上限值 9
	{
		usTemp = (quint16)(pAlarmParam->fBankSocUpLimitWarn * 10);
		iRetVal = 0;
	}
    else if (10 == usRegAddr) //簇SOC预警下限值 20
	{
		usTemp = (quint16)(pAlarmParam->fBankSocDownLimitWarn * 10);
		iRetVal = 0;
	}
    else if (11 == usRegAddr) //环境温度预警上限值 21
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempUpLimitWarn * 10 + 1000);
		iRetVal = 0;
	}
    else if (12 == usRegAddr) //环境温度预警下限值 22
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempDownLimitWarn * 10 + 1000);
		iRetVal = 0;
	}
    else if (13 == usRegAddr) //动力线温度预警上限 23
	{
		usTemp = (quint16)(pAlarmParam->fPowerLineTempUpLimitWarn * 10 + 1000);
		iRetVal = 0;
	}
    else if (14 == usRegAddr) //充电温度预警上限值 24
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempUpLimitWarn * 10 + 1000);
		iRetVal = 0;
	}
    else if (15 == usRegAddr) //充电温度预警下限值 25
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempDownLimitWarn * 10 + 1000);
		iRetVal = 0;
	}
    else if (16 == usRegAddr) //放电温度预警上限值 26
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempUpLimitWarn * 10 + 1000);
		iRetVal = 0;
	}
    else if (17 == usRegAddr) //放电温度预警下限值 27
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempDownLimitWarn * 10 + 1000);
		iRetVal = 0;
	}
    else if (18 == usRegAddr) //单体温度预警上限值 28
	{
		usTemp = (quint16)(pAlarmParam->fSglTempUpLimitWarn * 10 + 1000);
		iRetVal = 0;
	}
    else if (19 == usRegAddr) //单体温度预警下限值 29
	{
		usTemp = (quint16)(pAlarmParam->fSglTempDownLimitWarn * 10 + 1000);
		iRetVal = 0;
	}
    else if (20 == usRegAddr) //正极绝缘内阻预警下限值 20
	{
        usTemp = (quint16)(pAlarmParam->fPosResDownLimitWarn * 1000);
		iRetVal = 0;
	}
    else if (21 == usRegAddr) //负极绝缘内阻预警下限值 21
	{
        usTemp = (quint16)(pAlarmParam->fNegResDownLimitWarn * 1000);
		iRetVal = 0;
	}
    else if (22 == usRegAddr) //箱压差上限预警值 22
	{
        usTemp = (quint16)(pAlarmParam->fPackVolDiffUpLimitWarn);
		iRetVal = 0;
	}
    else if (23 == usRegAddr) //箱温差上限预警值 23
	{
        usTemp = (quint16)(pAlarmParam->fPackTempDiffUpLimitWarn * 10);
		iRetVal = 0;
	}
    else if (24 == usRegAddr) //簇端电压告警上限值 3
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitAlarm * 10);
		iRetVal = 0;
	}
    else if (25 == usRegAddr) //簇端电压告警下限值 4
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitAlarm * 10);
		iRetVal = 0;
	}
    else if (26 == usRegAddr) //充电电流告警上限值 5
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitAlarm * 10);
		iRetVal = 0;
	}
    else if (27 == usRegAddr) //放电电流告警上限值 6
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitAlarm * 10);
		iRetVal = 0;
	}
    else if (28 == usRegAddr) //单体电压告警上限值 7
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitAlarm * 1000);
		iRetVal = 0;
	}
    else if (29 == usRegAddr) //单体电压告警下限值 8
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitAlarm * 1000);
		iRetVal = 0;
	}
    else if (30 == usRegAddr) //簇SOC告警上限值 9
	{
		usTemp = (quint16)(pAlarmParam->fBankSocUpLimitAlarm * 10);
		iRetVal = 0;
	}
    else if (31 == usRegAddr) //簇SOC告警下限值 20
	{
		usTemp = (quint16)(pAlarmParam->fBankSocDownLimitAlarm * 10);
		iRetVal = 0;
	}
    else if (32 == usRegAddr) //环境温度告警上限值 21
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempUpLimitAlarm * 10 + 1000);
		iRetVal = 0;
	}
    else if (33 == usRegAddr) //环境温度告警下限值 22
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempDownLimitAlarm * 10 + 1000);
		iRetVal = 0;
	}
    else if (34 == usRegAddr) //动力线温度告警上限 23
	{
		usTemp = (quint16)(pAlarmParam->fPowerLineTempUpLimitAlarm * 10 + 1000);
		iRetVal = 0;
	}
    else if (35 == usRegAddr) //充电温度告警上限值 24
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempUpLimitAlarm * 10 + 1000);
		iRetVal = 0;
	}
    else if (36 == usRegAddr) //充电温度告警下限值 25
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempDownLimitAlarm * 10 + 1000);
		iRetVal = 0;
	}
    else if (37 == usRegAddr) //放电温度告警上限值 26
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempUpLimitAlarm * 10 + 1000);
		iRetVal = 0;
	}
    else if (38 == usRegAddr) //放电温度告警下限值 27
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempDownLimitAlarm * 10 + 1000);
		iRetVal = 0;
	}
    else if (39 == usRegAddr) //单体温度告警上限值 28
	{
		usTemp = (quint16)(pAlarmParam->fSglTempUpLimitAlarm * 10 + 1000);
		iRetVal = 0;
	}
    else if (40 == usRegAddr) //单体温度告警下限值 29
	{
		usTemp = (quint16)(pAlarmParam->fSglTempDownLimitAlarm * 10 + 1000);
		iRetVal = 0;
	}
    else if (41 == usRegAddr) //正极绝缘内阻告警下限值 20
	{
        usTemp = (quint16)(pAlarmParam->fPosResDownLimitAlarm * 1000);
		iRetVal = 0;
	}
    else if (42 == usRegAddr) //负极绝缘内阻告警下限值 21
	{
        usTemp = (quint16)(pAlarmParam->fNegResDownLimitAlarm * 1000);
		iRetVal = 0;
	}
    else if (43 == usRegAddr) //箱压差上限告警值 22
	{
        usTemp = (quint16)(pAlarmParam->fPackVolDiffUpLimitAlarm);
		iRetVal = 0;
	}
    else if (44 == usRegAddr) //箱温差上限告警值 23
	{
        usTemp = (quint16)(pAlarmParam->fPackTempDiffUpLimitAlarm * 10);
		iRetVal = 0;
	}
    else if (45 == usRegAddr) //簇端电压保护上限值 3
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitProt * 10);
		iRetVal = 0;
	}
    else if (46 == usRegAddr) //簇端电压保护下限值 4
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitProt * 10);
		iRetVal = 0;
	}
    else if (47 == usRegAddr) //充电电流保护上限值 5
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitProt * 10);
		iRetVal = 0;
	}
    else if (48 == usRegAddr) //放电电流保护上限值 6
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitProt * 10);
		iRetVal = 0;
	}
    else if (49 == usRegAddr) //单体电压保护上限值 7
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitProt * 1000);
		iRetVal = 0;
	}
    else if (50 == usRegAddr) //单体电压保护下限值 8
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitProt * 1000);
		iRetVal = 0;
	}
    else if (51 == usRegAddr) //簇SOC保护上限值 9
	{
		usTemp = (quint16)(pAlarmParam->fBankSocUpLimitProt * 10);
		iRetVal = 0;
	}
    else if (52 == usRegAddr) //簇SOC保护下限值 20
	{
		usTemp = (quint16)(pAlarmParam->fBankSocDownLimitProt * 10);
		iRetVal = 0;
	}
    else if (53 == usRegAddr) //环境温度保护上限值 21
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempUpLimitProt * 10 + 1000);
		iRetVal = 0;
	}
    else if (54 == usRegAddr) //环境温度保护下限值 22
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempDownLimitProt * 10 + 1000);
		iRetVal = 0;
	}
    else if (55 == usRegAddr) //动力线温度保护上限 23
	{
		usTemp = (quint16)(pAlarmParam->fPowerLineTempUpLimitProt * 10 + 1000);
		iRetVal = 0;
	}
    else if (56 == usRegAddr) //充电温度保护上限值 24
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempUpLimitProt * 10 + 1000);
		iRetVal = 0;
	}
    else if (57 == usRegAddr) //充电温度保护下限值 25
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempDownLimitProt * 10 + 1000);
		iRetVal = 0;
	}
    else if (58 == usRegAddr) //放电温度保护上限值 26
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempUpLimitProt * 10 + 1000);
		iRetVal = 0;
	}
    else if (59 == usRegAddr) //放电温度保护下限值 27
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempDownLimitProt * 10 + 1000);
		iRetVal = 0;
	}
    else if (60 == usRegAddr) //单体温度保护上限值 28
	{
		usTemp = (quint16)(pAlarmParam->fSglTempUpLimitProt * 10 + 1000);
		iRetVal = 0;
	}
    else if (61 == usRegAddr) //单体温度保护下限值 29
	{
		usTemp = (quint16)(pAlarmParam->fSglTempDownLimitProt * 10 + 1000);
		iRetVal = 0;
	}
    else if (62 == usRegAddr) //正极绝缘内阻保护下限值 20
	{
        usTemp = (quint16)(pAlarmParam->fPosResDownLimitProt * 1000);
		iRetVal = 0;
	}
    else if (63 == usRegAddr) //负极绝缘内阻保护下限值 21
	{
        usTemp = (quint16)(pAlarmParam->fNegResDownLimitProt * 1000);
		iRetVal = 0;
	}
    else if (64 == usRegAddr) //箱压差上限保护值 22
	{
        usTemp = (quint16)(pAlarmParam->fPackVolDiffUpLimitProt);
		iRetVal = 0;
	}
    else if (65 == usRegAddr) //箱温差上限保护值 23
	{
        usTemp = (quint16)(pAlarmParam->fPackTempDiffUpLimitProt * 10);
		iRetVal = 0;
	}
    else if (66 == usRegAddr) //簇端电压预警回差上限值 3
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (67 == usRegAddr) //簇端电压预警回差下限值 4
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (68 == usRegAddr) //充电电流预警回差上限值 5
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (69 == usRegAddr) //放电电流预警回差上限值 6
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (70 == usRegAddr) //单体电压预警回差上限值 7
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitWarnHC * 1000);
		iRetVal = 0;
	}
    else if (71 == usRegAddr) //单体电压预警回差下限值 8
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitWarnHC * 1000);
		iRetVal = 0;
	}
    else if (72 == usRegAddr) //簇SOC预警回差上限值 9
	{
		usTemp = (quint16)(pAlarmParam->fBankSocUpLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (73 == usRegAddr) //簇SOC预警回差下限值 20
	{
		usTemp = (quint16)(pAlarmParam->fBankSocDownLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (74 == usRegAddr) //环境温度预警回差上限值 21
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempUpLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (75 == usRegAddr) //环境温度预警回差下限值 22
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempDownLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (76 == usRegAddr) //动力线温度预警回差上限 23
	{
		usTemp = (quint16)(pAlarmParam->fPowerLineTempUpLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (77 == usRegAddr) //充电温度预警回差上限值 24
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempUpLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (78 == usRegAddr) //充电温度预警回差下限值 25
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempDownLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (79 == usRegAddr) //放电温度预警回差上限值 26
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempUpLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (80 == usRegAddr) //放电温度预警回差下限值 27
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempDownLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (81 == usRegAddr) //单体温度预警回差上限值 28
	{
		usTemp = (quint16)(pAlarmParam->fSglTempUpLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (82 == usRegAddr) //单体温度预警回差下限值 29
	{
		usTemp = (quint16)(pAlarmParam->fSglTempDownLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (83 == usRegAddr) //正极绝缘内阻预警回差下限值 20
	{
        usTemp = (quint16)(pAlarmParam->fPosResDownLimitWarnHC * 1000);
		iRetVal = 0;
	}
    else if (84 == usRegAddr) //负极绝缘内阻预警回差下限值 21
	{
        usTemp = (quint16)(pAlarmParam->fNegResDownLimitWarnHC * 1000);
		iRetVal = 0;
	}
    else if (85 == usRegAddr) //箱压差上限预警回差值 22
	{
        usTemp = (quint16)(pAlarmParam->fPackVolDiffUpLimitWarnHC);
		iRetVal = 0;
	}
    else if (86 == usRegAddr) //箱温差上限预警回差值 23
	{
        usTemp = (quint16)(pAlarmParam->fPackTempDiffUpLimitWarnHC * 10);
		iRetVal = 0;
	}
    else if (87 == usRegAddr) //簇端电压告警回差上限值 3
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (88 == usRegAddr) //簇端电压告警回差下限值 4
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (89 == usRegAddr) //充电电流告警回差上限值 5
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (90 == usRegAddr) //放电电流告警回差上限值 6
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (91 == usRegAddr) //单体电压告警回差上限值 7
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitAlarmHC * 1000);
		iRetVal = 0;
	}
    else if (92 == usRegAddr) //单体电压告警回差下限值 8
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitAlarmHC * 1000);
		iRetVal = 0;
	}
    else if (93 == usRegAddr) //簇SOC告警回差上限值 9
	{
		usTemp = (quint16)(pAlarmParam->fBankSocUpLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (94 == usRegAddr) //簇SOC告警回差下限值 20
	{
		usTemp = (quint16)(pAlarmParam->fBankSocDownLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (95 == usRegAddr) //环境温度告警回差上限值 21
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempUpLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (96 == usRegAddr) //环境温度告警回差下限值 22
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempDownLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (97 == usRegAddr) //动力线温度告警回差上限 23
	{
		usTemp = (quint16)(pAlarmParam->fPowerLineTempUpLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (98 == usRegAddr) //充电温度告警回差上限值 24
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempUpLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (99 == usRegAddr) //充电温度告警回差下限值 25
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempDownLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (100 == usRegAddr) //放电温度告警回差上限值 26
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempUpLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (101 == usRegAddr) //放电温度告警回差下限值 27
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempDownLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (102 == usRegAddr) //单体温度告警回差上限值 28
	{
		usTemp = (quint16)(pAlarmParam->fSglTempUpLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (103 == usRegAddr) //单体温度告警回差下限值 29
	{
		usTemp = (quint16)(pAlarmParam->fSglTempDownLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (104 == usRegAddr) //正极绝缘内阻告警回差下限值 20
	{
        usTemp = (quint16)(pAlarmParam->fPosResDownLimitAlarmHC * 1000);
		iRetVal = 0;
	}
    else if (105 == usRegAddr) //负极绝缘内阻告警回差下限值 21
	{
        usTemp = (quint16)(pAlarmParam->fNegResDownLimitAlarmHC * 1000);
		iRetVal = 0;
	}
    else if (106 == usRegAddr) //箱压差上限告警回差值 22
	{
        usTemp = (quint16)(pAlarmParam->fPackVolDiffUpLimitAlarmHC);
		iRetVal = 0;
	}
    else if (107 == usRegAddr) //箱温差上限告警回差值 23
	{
        usTemp = (quint16)(pAlarmParam->fPackTempDiffUpLimitAlarmHC * 10);
		iRetVal = 0;
	}
    else if (108 == usRegAddr) //簇端电压保护回差上限值 3
	{
		usTemp = (quint16)(pAlarmParam->fBankVolUpLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (109 == usRegAddr) //簇端电压保护回差下限值 4
	{
		usTemp = (quint16)(pAlarmParam->fBankVolDownLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (110 == usRegAddr) //充电电流保护回差上限值 5
	{
		usTemp = (quint16)(pAlarmParam->fChargeCurUpLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (111 == usRegAddr) //放电电流保护回差上限值 6
	{
		usTemp = (quint16)(pAlarmParam->fDischargeCurUpLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (112 == usRegAddr) //单体电压保护回差上限值 7
	{
		usTemp = (quint16)(pAlarmParam->fSglVolUpLimitProtHC * 1000);
		iRetVal = 0;
	}
    else if (113 == usRegAddr) //单体电压保护回差下限值 8
	{
		usTemp = (quint16)(pAlarmParam->fSglVolDownLimitProtHC * 1000);
		iRetVal = 0;
	}
    else if (114 == usRegAddr) //簇SOC保护回差上限值 9
	{
		usTemp = (quint16)(pAlarmParam->fBankSocUpLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (115 == usRegAddr) //簇SOC保护回差下限值 20
	{
		usTemp = (quint16)(pAlarmParam->fBankSocDownLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (116 == usRegAddr) //环境温度保护回差上限值 21
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempUpLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (117 == usRegAddr) //环境温度保护回差下限值 22
	{
		usTemp = (quint16)(pAlarmParam->fEnvTempDownLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (118 == usRegAddr) //动力线温度保护回差上限 23
	{
		usTemp = (quint16)(pAlarmParam->fPowerLineTempUpLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (119 == usRegAddr) //充电温度保护回差上限值 24
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempUpLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (120 == usRegAddr) //充电温度保护回差下限值 25
	{
		usTemp = (quint16)(pAlarmParam->fChargeSglTempDownLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (121 == usRegAddr) //放电温度保护回差上限值 26
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempUpLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (122 == usRegAddr) //放电温度保护回差下限值 27
	{
		usTemp = (quint16)(pAlarmParam->fDchargeSglTempDownLimitProtHC * 10);
		iRetVal = 0;
	}
#ifdef XNWIN
    if (123 == usRegAddr) //单体温度保护回差上限值 28
#else
    else if (123 == usRegAddr) //单体温度保护回差上限值 28
#endif	
	{
		usTemp = (quint16)(pAlarmParam->fSglTempUpLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (124 == usRegAddr) //单体温度保护回差下限值 29
	{
		usTemp = (quint16)(pAlarmParam->fSglTempDownLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (125 == usRegAddr) //正极绝缘内阻保护回差下限值 20
	{
        usTemp = (quint16)(pAlarmParam->fPosResDownLimitProtHC * 1000);
		iRetVal = 0;
	}
    else if (126 == usRegAddr) //负极绝缘内阻保护回差下限值 21
	{
        usTemp = (quint16)(pAlarmParam->fNegResDownLimitProtHC * 1000);
		iRetVal = 0;
	}
    else if (127 == usRegAddr) //箱压差上限保护回差值 22
	{
        usTemp = (quint16)(pAlarmParam->fPackVolDiffUpLimitProtHC);
		iRetVal = 0;
	}
    else if (128 == usRegAddr) //箱温差上限保护回差值 23
	{
        usTemp = (quint16)(pAlarmParam->fPackTempDiffUpLimitProtHC * 10);
		iRetVal = 0;
	}
    else if (usRegAddr >= 129 && usRegAddr <= 178) //usBankHoldTemp 229 - 178
	{
		usTemp = pBattBank->usBankHoldTemp[usRegAddr - 129];
		iRetVal = 0;
	}

    //else if (129 == usRegAddr) //单体SOC差告警上限值
	//{
    //	usTemp = (quint16)(pAlarmParam->fSglSocDiffUpLimitAlarm * 10);
	//	iRetVal = 0;
	//}
    //else if (130 == usRegAddr) //单体SOH告警下限值
	//{
    //	usTemp = (quint16)(pAlarmParam->fSglSohDownLimitAlarm * 10);
	//	iRetVal = 0;
	//}
    //else if (131 == usRegAddr) //单体SOC差上限告警回差值
	//{
    //	usTemp = (quint16)(pAlarmParam->fSglSocDiffUpLimitAlarmHC * 10);
	//	iRetVal = 0;
	//}
    //else if (132 == usRegAddr) //单体SOH下限告警回差值
	//{
    //	usTemp = (quint16)(pAlarmParam->fSglSohDownLimitAlarmHC * 10);
	//	iRetVal = 0;
	//}
    else if (200 == usRegAddr) //簇端电压调整步长(系数) 37
	{
		usTemp = (quint16)(pBattBank->fBankVolCoe * 10 + 1000);
		iRetVal = 0;
	}
    else if (201 == usRegAddr) //充电电流调整步长(系数) 38
	{
		usTemp = (quint16)(pBattBank->fChargeCurCoe * 10 + 1000);
		iRetVal = 0;
	}
    else if (202 == usRegAddr) //放电电流调整步长(系数) 39
	{
        usTemp = (quint16)(pBattBank->fDischargeCurCoe * 10 + 1000);
		iRetVal = 0;
	}
    else if (203 == usRegAddr) //环境温度调整步长(系数) 40
	{
        usTemp = (quint16)(pBattBank->fEnvTempCoe * 10 + 1000);
		iRetVal = 0;
	}
    else if (204 == usRegAddr) //单体电压调整步长(系数) 41
	{
		usTemp = (quint16)(pBattBank->fSglVolCoe * 10 + 1000);
		iRetVal = 0;
	}
    else if (205 == usRegAddr) //单体温度调整步长(系数) 42
	{
		usTemp = (quint16)(pBattBank->fSglTempCoe * 10 + 1000);
		iRetVal = 0;
	}
    else if (206 == usRegAddr) //SOC标定基准上限值调整步长(系数) 43
	{
		usTemp = (quint16)(pBattBank->fBankSocRefUpLmtCoe * 10 + 1000); 		
		iRetVal = 0;
	}
    else if (207 == usRegAddr) //SOC标定基准下限值调整步长(系数) 44
	{
		usTemp = (quint16)(pBattBank->fBankSocRefDownLmtCoe * 10 + 1000); 
		iRetVal = 0;
	}
	else
	{
		iRetVal = -2;
	}

	if (0 == iRetVal)
	{
		addParam2Buffer(pData, usTemp);
	}

    return iRetVal;
}

// 保持寄存器 - UINT16 类型
// 0 - 正确处理
// -1 - 错误
// -2 - 地址错误
int CModbusFactory::addHoldRegVal2BufferStack(char* pData, quint16 usRegAddr, CBattStack* pBattStack)
{
	if (!pData || !pBattStack)
	{
		return -1;
	}

	int iRetVal = -999;
	quint16 usTemp = 0;
    if (1 == usRegAddr) //接触器断开前延时时间 2
	{
		usTemp = pBattStack->usDelayBeforeCutCntor;
		iRetVal = 0;
	}
	else if (2 == usRegAddr)
	{
		usTemp = pBattStack->usYear;
		iRetVal = 0;
	}
	else if (3 == usRegAddr)
	{
		usTemp = pBattStack->usMonth;
		iRetVal = 0;
	}
	else if (4 == usRegAddr)
	{
		usTemp = pBattStack->usDay;
		iRetVal = 0;
	}
	else if (5 == usRegAddr)
	{
		usTemp = pBattStack->usHour;
		iRetVal = 0;
	}
	else if (6 == usRegAddr)
	{
		usTemp = pBattStack->usMin;
		iRetVal = 0;
	}
	else if (7 == usRegAddr)
	{
		usTemp = pBattStack->usSec;
		iRetVal = 0;
	}
	else if (8 == usRegAddr)
	{
		usTemp = pBattStack->usConfirmDt;
		iRetVal = 0;
	}
	else if (9 == usRegAddr)
	{
		usTemp = pBattStack->usEMSContCtrl;
		iRetVal = 0;
	}
	else if (10 == usRegAddr)
	{
		usTemp = pBattStack->usEMSConfCtrl;
		iRetVal = 0;
	}
	else if (11 == usRegAddr)
	{
		usTemp = pBattStack->usEMSFaultClear;
		iRetVal = 0;
	}
	else if (12 == usRegAddr)
	{
		usTemp = pBattStack->usFtpIP1;
		iRetVal = 0;
	}
	else if (13 == usRegAddr)
	{
		usTemp = pBattStack->usFtpIP2;
		iRetVal = 0;
	}
	else if (14 == usRegAddr)
	{
		usTemp = pBattStack->usFtpIP3;
		iRetVal = 0;
	}
	else if (15 == usRegAddr)
	{
		usTemp = pBattStack->usFtpIP4;
		iRetVal = 0;
	}
	else if (16 == usRegAddr)
	{
		usTemp = pBattStack->usEMSNotifyUpgrade;
		iRetVal = 0;
	}
	else if (usRegAddr >= 30 && usRegAddr <= 79)
	{
        //50个数簇值
		usTemp = pBattStack->usStackHoldTemp[usRegAddr - 30];
		iRetVal = 0;
	}
	else
	{
		iRetVal = -2;
	}
	
	if (0 == iRetVal)
	{
		addParam2Buffer(pData, usTemp);
	}

    return iRetVal;
}

//增加环境变量数据到发送缓冲区
//返回处理的寄存器个数(一个寄存器两个字节)
//quint16类型返回1，float类型返回2
quint16 CModbusFactory::addRegVal2BufferEnv(char* pData, quint16 usRegAddr, CBattStack* pBattStack, int iModbusAddress)
{
    if (0 == pData || 0 == pBattStack)
	{
        return 1; //跳过该寄存器
	}

	quint16 usRetVal = 1;
	quint16 usTemp = 0;
	float fTemp = 0;

    //获取环境变量的quint16/float值
    int iRetVal = getRegValEnv(iModbusAddress, usRegAddr, pBattStack, usTemp, fTemp);
	if (1 == iRetVal)
	{
        //quint16值
		addParam2Buffer(pData, usTemp);
		usRetVal = 1;
	}
	else if (2 == iRetVal)
	{
        //float值
		addParam2Buffer(pData, fTemp);
		usRetVal = 2;
	}
	else
	{
		usRetVal = 1;
	}

    KG_LOG_INFO(QString("环境变量 usRegAddr=%1 usRetVal=%2 usTemp=%3 fTemp=%4").arg(usRegAddr).arg(usRetVal).arg(usTemp).arg(fTemp));

	return usRetVal;
}

// 返回处理的寄存器个数
// 一个寄存器两个字节
quint16 CModbusFactory::addRegVal2BufferStack(char* pData, quint16 usRegAddr, CBattStack* pBattStack)
{
    if (0 == pData || 0 == pBattStack)
	{
        return 1; //跳过该寄存器
	}

	quint16 usRetVal = 1;
	quint16 usTemp = 0;
	float fTemp = 0;

    //获取电池堆的相关变量的quint16/float值
	int iRetVal = getRegValStack(usRegAddr, pBattStack, usTemp, fTemp);
	if (1 == iRetVal)
	{
        //quint16值
		addParam2Buffer(pData, usTemp);
		usRetVal = 1;
	}
	else if (2 == iRetVal)
	{
        //float值
		addParam2Buffer(pData, fTemp);
		usRetVal = 2;
	}
	else
	{
		usRetVal = 1;
	}

	return usRetVal;
}

// -1 - Not find
// 2 - quint16 类型
// 2 - float 类型
//获取电池堆的环境变量的quint16/float值
int CModbusFactory::getRegValEnv(int iModbusAddress, quint16 usRegAddr, CBattStack* pBattStack, quint16& usVal, float& fVal)
{
    if (iModbusAddress < CModbusAddress::ENV_DATA_MIN)
    {
        return -1;
    }

    if (iModbusAddress > CModbusAddress::ENV_DATA_MAX)
    {
        return -1;
    }

    if (0 == pBattStack)
	{
		return -1;
	}

    int iDevIndex = iModbusAddress - CModbusAddress::ENV_DATA_MIN;

	// some variables
    int iRetVal = -1;

    if (IsAcReg(usRegAddr))
    {
        iRetVal = getRegValAc(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsThReg(usRegAddr))
    {
        iRetVal = getRegValTh(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsWaterReg(usRegAddr))
    {
        iRetVal = getRegValWater(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsFireReg(usRegAddr))
    {
        iRetVal = getRegValFire(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsLcReg(usRegAddr))
    {
        iRetVal = getRegValLc(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsPcsReg(usRegAddr))
    {
        iRetVal = getRegValPcs(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsMeterReg(usRegAddr))
    {
        iRetVal = getRegValMeter(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsEcReg(usRegAddr))
    {
        iRetVal = getRegValEc(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsDoorReg(usRegAddr))
    {
        iRetVal = getRegValDoor(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsGasReg(usRegAddr))
    {
        iRetVal = getRegValGas(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsDcdcReg(usRegAddr))
    {
        iRetVal = getRegValDcdc(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsCpReg(usRegAddr))
    {
        iRetVal = getRegValCp(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsDhReg(usRegAddr))
    {
        iRetVal = getRegValDh(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsFanReg(usRegAddr))
    {
        iRetVal = getRegValFan(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsStsReg(usRegAddr))
    {
        iRetVal = getRegValSts(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsPressReg(usRegAddr))
    {
        iRetVal = getRegValPress(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsLevelReg(usRegAddr))
    {
        iRetVal = getRegValLevel(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsPvReg(usRegAddr))
    {
        iRetVal = getRegValPv(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsUpsReg(usRegAddr))
    {
        iRetVal = getRegValUps(iDevIndex, usRegAddr, usVal, fVal);
    }
    else if (IsLedReg(usRegAddr))
    {
        iRetVal = getRegValLed(iDevIndex, usRegAddr, usVal, fVal);
    }

    KG_LOG_INFO(QString("获取动环数据iModbusAddress=%1 iDevIndex=%2 usRegAddr=%3 usVal=%4 fVal=%5 iRetVal=%6")
                .arg(iModbusAddress).arg(iDevIndex).arg(usRegAddr)
                .arg(usVal).arg(fVal,0, 'f', 2).arg(iRetVal));

	return iRetVal;
}

int CModbusFactory::getRegValAc(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_AC_NUM)
    {
        return -1;
    }

    CAcData* pDev = 0;
    pDev = m_pRtdb->getAcDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= AC_REG_INT_MIN && usRegAddr <= AC_REG_INT_MAX)
    {
        //读空调的UINT16数据(200个)
        iRetVal = 1;

        if ((AC_REG_INT_MIN+0) == usRegAddr)
        {
            // 1 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((AC_REG_INT_MIN+1) == usRegAddr)
        {
            // 2 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((AC_REG_INT_MIN+2) == usRegAddr)
        {
            // 3 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((AC_REG_INT_MIN+3) == usRegAddr)
        {
            // 4 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((AC_REG_INT_MIN+4) == usRegAddr)
        {
            // 5 RO 室内风机状态 UINT16 1 0
            usVal = pDev->m_uInsideFanState;
        }
        else if ((AC_REG_INT_MIN+5) == usRegAddr)
        {
            // 6 RO 室外风机状态 UINT16 1 0
            usVal = pDev->m_uOutsideFanState;
        }
        else if ((AC_REG_INT_MIN+6) == usRegAddr)
        {
            // 7 RO 压缩机状态 UINT16 1 0
            usVal = pDev->m_uCoolerState;
        }
        else if ((AC_REG_INT_MIN+7) == usRegAddr)
        {
            // 8 RO 电加热运行状态 UINT16 1 0
            usVal = pDev->m_uHeaterState;
        }
        else if ((AC_REG_INT_MIN+8) == usRegAddr)
        {
            // 9 RO 应急风机运行状态 UINT16 1 0
            usVal = pDev->m_uEmergencyFanState;
        }
        else if ((AC_REG_INT_MIN+9) == usRegAddr)
        {
            // 10 RO 调试开关状态 UINT16 1 0 0--关闭，1--开启
            usVal = pDev->m_uDebugState;
        }
        else if ((AC_REG_INT_MIN+10) == usRegAddr)
        {
            // 11 RO 工作状态 UINT16 1 0 0待机 1制冷 2制热 3新风 4送风 5除湿
            usVal = pDev->m_uWorkState;
        }
        else if ((AC_REG_INT_MIN+10) == usRegAddr)
        {
            // 12 RO 故障状态 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uFaultState;
        }
        else if ((AC_REG_INT_MIN+10) == usRegAddr)
        {
            // 13 RO 除湿状态 UINT16 1 0 0--运行,1--停止
            usVal = pDev->m_uDryState;
        }
        else
        {
            // 14~200 RO 预留 UINT16 1 0值为0
            usVal = 0;
        }
    }
    else if (usRegAddr >= AC_REG_FLT_MIN && usRegAddr <= AC_REG_FLT_MAX)
    {
        //读空调的FLOAT数据(200个)
        iRetVal = 2;

        if ((AC_REG_FLT_MIN+0) == usRegAddr)
        {
            // 201 RO 室内温度 FLOAT 1 0 ℃
            fVal = pDev->m_fInsideTemp;
        }
        else if ((AC_REG_FLT_MIN+2) == usRegAddr)
        {
            // 203 RO 室内湿度 FLOAT 1 0 %
            fVal = pDev->m_fInsideHumi;
        }
        else if ((AC_REG_FLT_MIN+4) == usRegAddr)
        {
            // 205 RO 室外温度 FLOAT 1 0 ℃
            fVal = pDev->m_fOutsideTemp;
        }
        else if ((AC_REG_FLT_MIN+6) == usRegAddr)
        {
            // 207 RO 室外湿度 FLOAT 1 0 %
            fVal = pDev->m_fOutsideHumi;
        }
        else if ((AC_REG_FLT_MIN+8) == usRegAddr)
        {
            // 209 RO 冷凝温度 FLOAT 1 0 ℃
            fVal = pDev->m_fCondenseTemp;
        }
        else if ((AC_REG_FLT_MIN+10) == usRegAddr)
        {
            // 211 RO 排气温度 FLOAT 1 0 ℃
            fVal = pDev->m_fVentilateTemp;
        }
        else if ((AC_REG_FLT_MIN+12) == usRegAddr)
        {
            // 213 RO 柜内回风温度 FLOAT 1 0 ℃
            fVal = pDev->m_fInsideReturnTemp;
        }
        else if ((AC_REG_FLT_MIN+14) == usRegAddr)
        {
            // 215 RO 柜内回风湿度 FLOAT 1 0 %
            fVal = pDev->m_fInsideReturnHumi;
        }
        else if ((AC_REG_FLT_MIN+16) == usRegAddr)
        {
            // 217 RO 制冷开启温度 FLOAT 1 0 ℃
            fVal = pDev->m_fCoolStartTemp;
        }
        else if ((AC_REG_FLT_MIN+18) == usRegAddr)
        {
            // 219 RO 制冷停止温度 FLOAT 1 0 ℃
            fVal = pDev->m_fCoolStopTemp;
        }
        else if ((AC_REG_FLT_MIN+20) == usRegAddr)
        {
            // 221 RO 制冷回差温度 FLOAT 1 0 ℃
            fVal = pDev->m_fCoolDiffTemp;
        }
        else if ((AC_REG_FLT_MIN+22) == usRegAddr)
        {
            // 223 RO 制热开启温度 FLOAT 1 0 ℃
            fVal = pDev->m_fHeatStartTemp;
        }
        else if ((AC_REG_FLT_MIN+24) == usRegAddr)
        {
            // 225 RO 制热停止温度 FLOAT 1 0 ℃
            fVal = pDev->m_fHeatStopTemp;
        }
        else if ((AC_REG_FLT_MIN+26) == usRegAddr)
        {
            // 227 RO 制热回差温度 FLOAT 1 0 ℃
            fVal = pDev->m_fHeatDiffTemp;
        }
        else if ((AC_REG_FLT_MIN+28) == usRegAddr)
        {
            // 229 RO 除湿开启湿度 FLOAT 1 0 %
            fVal = pDev->m_fDryStartHumi;
        }
        else if ((AC_REG_FLT_MIN+30) == usRegAddr)
        {
            // 231 RO 已除湿停止湿度 FLOAT 1 0 %
            fVal = pDev->m_fDryStopHumi;
        }
        else if ((AC_REG_FLT_MIN+32) == usRegAddr)
        {
            // 233 RO 除湿回差湿度 FLOAT 1 0 %
            fVal = pDev->m_fDryDiffHumi;
        }
        else if ((AC_REG_FLT_MIN+34) == usRegAddr)
        {
            // 235 RO 调试下的单体最大温度 FLOAT 1 0 ℃
            fVal = pDev->m_fDebugSglMaxTemp;
        }
        else if ((AC_REG_FLT_MIN+36) == usRegAddr)
        {
            // 237 RO 调试下的单体最小温度 FLOAT 1 0 ℃
            fVal = pDev->m_fDebugSglMinTemp;
        }
        else if ((AC_REG_FLT_MIN+38) == usRegAddr)
        {
            // 239 RO 调试下的单体平均温度 FLOAT 1 0 ℃
            fVal = pDev->m_fDebugSglAvgTemp;
        }
        else if ((AC_REG_FLT_MIN+40) == usRegAddr)
        {
            // 241 RO 调试下的单体最大温差 FLOAT 1 0 ℃
            fVal = pDev->m_fDebugSglMaxTempDiff;
        }
        else if ((AC_REG_FLT_MIN+42) == usRegAddr)
        {
            // 243 RO 蒸发温度 FLOAT 1 0 ℃
            fVal = pDev->m_fEvaporateTemp;
        }
        else if ((AC_REG_FLT_MIN+44) == usRegAddr)
        {
            // 245 RO 交流电压 FLOAT 1 0 V
            fVal = pDev->m_fAcVol;
        }
        else if ((AC_REG_FLT_MIN+46) == usRegAddr)
        {
            // 247 RO 直流电压 FLOAT 1 0 A
            fVal = pDev->m_fDcVol;
        }
        else if ((AC_REG_FLT_MIN+48) == usRegAddr)
        {
            // 249 RO 目标开始温度 FLOAT 1 0 ℃
            fVal = pDev->m_fTargetStartTemp;
        }
        else if ((AC_REG_FLT_MIN+50) == usRegAddr)
        {
            // 251 RO 目标停止温度 FLOAT 1 0 ℃
            fVal = pDev->m_fTargetStopTemp;
        }
        else if ((AC_REG_FLT_MIN+52) == usRegAddr)
        {
            // 253 RO 目标回差温度 FLOAT 1 0 ℃
            fVal = pDev->m_fTargetDiffTemp;
        }
        else if ((AC_REG_FLT_MIN+54) == usRegAddr)
        {
            // 255 RO 目标开始湿度 FLOAT 1 0 %
            fVal = pDev->m_fTargetStartHumi;
        }
        else if ((AC_REG_FLT_MIN+56) == usRegAddr)
        {
            // 257 RO 目标停止湿度 FLOAT 1 0 %
            fVal = pDev->m_fTargetStopHumi;
        }
        else if ((AC_REG_FLT_MIN+58) == usRegAddr)
        {
            // 259 RO 目标回差湿度 FLOAT 1 0 %
            fVal = pDev->m_fTargetDiffHumi;
        }
        else
        {
            //261~599 预留
            fVal = 0.0;
        }
    }
    else if (usRegAddr >= AC_REG_SET_MIN && usRegAddr <= AC_REG_SET_MAX)
    {
        //读空调的下设的UINT16数据(200个)
        iRetVal = 1;

        if ((AC_REG_SET_MIN+0) == usRegAddr)
        {
            // 30001 RW 开关机 UINT16 1 0 0未知,1关机,2开机,默认为0
            usVal = pDev->m_uSetSwitchState;
        }
        else if ((AC_REG_SET_MIN+1) == usRegAddr)
        {
            // 30002 RW 启动制冷命令 UINT16 1 0 0未知,1关闭,2启动,默认为0
            usVal = pDev->m_uSetStartCoolCmd;
        }
        else if ((AC_REG_SET_MIN+2) == usRegAddr)
        {
            // 30003 RW 启动制热命令 UINT16 1 0 0未知,1关闭,2启动,默认为0
            usVal = pDev->m_uSetStartHotCmd;
        }
        else if ((AC_REG_SET_MIN+3) == usRegAddr)
        {
            // 30004 RW 启动待机命令 UINT16 1 0 0未知,1关闭,2启动,默认为0
            usVal = pDev->m_uSetStartWaitCmd;
        }
        else if ((AC_REG_SET_MIN+4) == usRegAddr)
        {
            // 30005 RW 启动送风命令 UINT16 1 0 0未知,1关闭,2启动,默认为0
            usVal = pDev->m_uSetStartWindCmd;
        }
        else if ((AC_REG_SET_MIN+5) == usRegAddr)
        {
            // 30006 RW 启动除湿命令 UINT16 1 0 0未知,1关闭,2启动,默认为0
            usVal = pDev->m_uSetStartDryCmd;
        }
        else if ((AC_REG_SET_MIN+6) == usRegAddr)
        {
            // 30007 RW 下设的开启温度 UINT16 0.01 -100 ℃	"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetStartTemp+100)*100;
        }
        else if ((AC_REG_SET_MIN+7) == usRegAddr)
        {
            // 30008 RW 下设的停止温度 UINT16 0.01 -100 ℃
            usVal = (quint16) (pDev->m_fSetStopTemp+100)*100;
        }
        else if ((AC_REG_SET_MIN+8) == usRegAddr)
        {
            // 30009 RW 下设的制冷开始温度 UINT16 0.01 -100 ℃
            usVal = (quint16) (pDev->m_fSetCoolStartTemp+100)*100;
        }
        else if ((AC_REG_SET_MIN+9) == usRegAddr)
        {
            // 30010 RW 下设的制冷停止温度 UINT16 0.01 -100 ℃
            usVal = (quint16) (pDev->m_fSetCoolStopTemp+100)*100;
        }
        else if ((AC_REG_SET_MIN+10) == usRegAddr)
        {
            // 30011 RW 下设的制冷温度回差 UINT16 0.01 -100 ℃
            usVal = (quint16) (pDev->m_fSetCoolDiffTemp+100)*100;
        }
        else if ((AC_REG_SET_MIN+11) == usRegAddr)
        {
            // 30012 RW 下设的制热开始温度 UINT16 0.01 -100 ℃
            usVal = (quint16) (pDev->m_fSetHotStartTemp+100)*100;
        }
        else if ((AC_REG_SET_MIN+12) == usRegAddr)
        {
            // 30013 RW 下设的制热停止温度 UINT16 0.01 -100 ℃
            usVal = (quint16) (pDev->m_fSetHotStopTemp+100)*100;
        }
        else if ((AC_REG_SET_MIN+13) == usRegAddr)
        {
            // 30014 RW 下设的制热温度回差 UINT16 0.01 -100 ℃
            usVal = (quint16) (pDev->m_fSetHotDiffTemp+100)*100;
        }
        else if ((AC_REG_SET_MIN+14) == usRegAddr)
        {
            // 30015 RW 下设的最高控制温度 UINT16 0.01 -100 ℃
            usVal = (quint16) (pDev->m_fSetCtrlTempMax+100)*100;
        }
        else if ((AC_REG_SET_MIN+15) == usRegAddr)
        {
            // 30016 RW 下设的最低控制温度 UINT16 0.01 -100 ℃
            usVal = (quint16) (pDev->m_fSetCtrlTempMin+100)*100;
        }
        else if ((AC_REG_SET_MIN+16) == usRegAddr)
        {
            // 30017 RW 下设的平均控制温度 UINT16 0.01 -100 ℃
            usVal = (quint16) (pDev->m_fSetCtrlTempAvg+100)*100;
        }
        else if ((AC_REG_SET_MIN+17) == usRegAddr)
        {
            // 30018 RW 下设的控制湿度 UINT16 0.01 -100 %
            usVal = (quint16) (pDev->m_fSetCtrlHumi+100)*100;
        }
        else if ((AC_REG_SET_MIN+18) == usRegAddr)
        {
            // 30019 RW 下设的开始湿度 UINT16 0.01 -100 %
            usVal = (quint16) (pDev->m_fSetStartHumi+100)*100;
        }
        else if ((AC_REG_SET_MIN+19) == usRegAddr)
        {
            // 30020 RW 下设的停止湿度 UINT16 0.01 -100 %
            usVal = (quint16) (pDev->m_fSetStopHumi+100)*100;
        }
        else
        {
            // 30021~30200 预留
            usVal = 0;
        }
    }

    return iRetVal;
}

int CModbusFactory::getRegValTh(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_TH_NUM)
    {
        return -1;
    }

    CThData* pDev = 0;
    pDev = m_pRtdb->getThDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= TH_REG_INT_MIN && usRegAddr <= TH_REG_INT_MAX)
    {
        //读温湿度的UINT16数据(200个)
        iRetVal = 1;

        if ((TH_REG_INT_MIN+0) == usRegAddr)
        {
            // 601 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        if ((TH_REG_INT_MIN+1) == usRegAddr)
        {
            // 602 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        if ((TH_REG_INT_MIN+2) == usRegAddr)
        {
            // 603 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        if ((TH_REG_INT_MIN+3) == usRegAddr)
        {
            // 604 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else
        {
            //605~800 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= TH_REG_FLT_MIN && usRegAddr <= TH_REG_FLT_MAX)
    {
        //读温湿度的FLOAT数据(200个)
        iRetVal = 2;

        if ((TH_REG_FLT_MIN+0) == usRegAddr)
        {
            // 801 RO 温湿度的室内温度 FLOAT 1 0 ℃
            fVal = pDev->m_fInsideTemp;
        }
        else if ((TH_REG_FLT_MIN+2) == usRegAddr)
        {
            // 803 RO 温湿度的室内湿度 FLOAT 1 0 %RH
            fVal = pDev->m_fInsideHumi;
        }
        else
        {
            //805~1199 预留
            fVal = 0.0;
        }
    }

    return iRetVal;
}

int CModbusFactory::getRegValWater(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_WATER_NUM)
    {
        return -1;
    }

    CWaterData* pDev = 0;
    pDev = m_pRtdb->getWaterDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= WATER_REG_INT_MIN && usRegAddr <= WATER_REG_INT_MAX)
    {
        //读水浸的UINT16数据(200个)
        iRetVal = 1;

        if ((WATER_REG_INT_MIN+0) == usRegAddr)
        {
            // 1201 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((WATER_REG_INT_MIN+1) == usRegAddr)
        {
            // 1202 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((WATER_REG_INT_MIN+2) == usRegAddr)
        {
            // 1203 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((WATER_REG_INT_MIN+3) == usRegAddr)
        {
            // 1204 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((WATER_REG_INT_MIN+4) == usRegAddr)
        {
            // 1205 RO 故障状态 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uAlarmState;
        }
        else if ((WATER_REG_INT_MIN+5) == usRegAddr)
        {
            // 1206 RO 告警使能 UINT16 1 0 0--禁用,1--启用
            usVal = pDev->m_uAlarmState;
        }
        else if ((WATER_REG_INT_MIN+6) == usRegAddr)
        {
            // 1207 RO 故障使能 UINT16 1 0 0--禁用,1--启用
            usVal = pDev->m_uAlarmState;
        }
        else
        {
            //1208~1400 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= WATER_REG_FLT_MIN && usRegAddr <= WATER_REG_FLT_MAX)
    {
        //读水浸的FLOAT数据(200个)
        iRetVal = 2;

        //1401~1799 预留
        fVal = 0.0;
    }

    return iRetVal;
}

int CModbusFactory::getRegValFire(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_FIRE_NUM)
    {
        return -1;
    }

    CFireData* pDev = 0;
    pDev = m_pRtdb->getFireDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= FIRE_REG_INT_MIN && usRegAddr <= FIRE_REG_INT_MAX)
    {
        //读消防的UINT16数据(200个)
        iRetVal = 1;

        if ((FIRE_REG_INT_MIN+0) == usRegAddr)
        {
            // 1801 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((FIRE_REG_INT_MIN+1) == usRegAddr)
        {
            // 1802 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((FIRE_REG_INT_MIN+2) == usRegAddr)
        {
            // 1803 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((FIRE_REG_INT_MIN+3) == usRegAddr)
        {
            // 1804 RO 告警等级 UINT16 1 0 0无,1一级告警,2二级告警,3三级告警,4四级告警
            usVal = pDev->m_uAlarmLevel;
        }
        else if ((FIRE_REG_INT_MIN+4) == usRegAddr)
        {
            // 1805 RO 消防启动 UINT16 1 0 0--未启动，1--已启动
            usVal = pDev->m_uFireAction;
        }
        else if ((FIRE_REG_INT_MIN+5) == usRegAddr)
        {
            // 1806 RO 消防告警 UINT16 1 0 0--无告警，1--有告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((FIRE_REG_INT_MIN+6) == usRegAddr)
        {
            // 1807 RO 消防故障 UINT16 1 0 0--无故障，1--有故障
            usVal = pDev->m_uFaultState;
        }
        else if ((FIRE_REG_INT_MIN+7) == usRegAddr)
        {
            // 1808 RO 数据来源 UINT16 1 0 0无来源,1通讯采集,2DI反馈
            usVal = pDev->m_uAlarmSource;
        }
        else if ((FIRE_REG_INT_MIN+8) == usRegAddr)
        {
            // 1809 RO 告警反馈的DI编号 UINT16 1 0 从1开始(数据来源为DI反馈时有效)
            usVal = pDev->m_uAlarmDiNo;
        }
        else if ((FIRE_REG_INT_MIN+9) == usRegAddr)
        {
            // 1810 RO 消防喷洒 UINT16 1 0 0未知,1未喷洒,2喷洒中
            usVal = pDev->m_uFireSpray;
        }
        else if ((FIRE_REG_INT_MIN+10) == usRegAddr)
        {
            // 1811 RO 消防恢复 UINT16 1 0 0未知,1未恢复,2已恢复
            usVal = pDev->m_uFireRecover;
        }
        else if ((FIRE_REG_INT_MIN+11) == usRegAddr)
        {
            // 1812 RO 告警使能 UINT16 1 0 0禁用,1开启
            usVal = pDev->m_uAlarmEnable;
        }
        else if ((FIRE_REG_INT_MIN+12) == usRegAddr)
        {
            // 1813 RO 故障使能 UINT16 1 0 0禁用,1开启
            usVal = pDev->m_uFaultEnable;
        }
        else if ((FIRE_REG_INT_MIN+13) == usRegAddr)
        {
            // 1814 RO 启动使能 UINT16 1 0 0禁用,1开启
            usVal = pDev->m_uStartEnable;
        }
        else
        {
            //1815~2000 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= FIRE_REG_FLT_MIN && usRegAddr <= FIRE_REG_FLT_MAX)
    {
        //读消防的FLOAT数据(200个)
        iRetVal = 2;

        if ((FIRE_REG_FLT_MIN+0) == usRegAddr)
        {
            // 2001 RO 有害气体浓度	FLOAT	1	0
            fVal = pDev->m_fHarmfulGasDensity;
        }
        if ((FIRE_REG_FLT_MIN+2) == usRegAddr)
        {
            // 2003 RO 可燃气体浓度	FLOAT	1	0
            fVal = pDev->m_fFlammableGasDensity;
        }
        else
        {
            //2005~2399 预留
            fVal = 0.0;
        }
    }

    return iRetVal;
}

int CModbusFactory::getRegValLc(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_LC_NUM)
    {
        return -1;
    }

    CLcData* pDev = 0;
    pDev = m_pRtdb->getLcDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= LC_REG_INT_MIN && usRegAddr <= LC_REG_INT_MAX)
    {
        //读液冷的UINT16数据(200个)
        iRetVal = 1;

        if ((LC_REG_INT_MIN+0) == usRegAddr)
        {
            // 2401 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((LC_REG_INT_MIN+1) == usRegAddr)
        {
            // 2402 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((LC_REG_INT_MIN+2) == usRegAddr)
        {
            // 2403 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((LC_REG_INT_MIN+3) == usRegAddr)
        {
            // 2404 RO 故障状态 UINT16 1 0 0正常 1故障
            usVal = pDev->m_uFaultState;
        }
        else if ((LC_REG_INT_MIN+4) == usRegAddr)
        {
            // 2405 RO 工作状态 UINT16 1 0 0待机 1制冷 2制热 3循环 4自动
            usVal = pDev->m_uWorkState;
        }
        else if ((LC_REG_INT_MIN+5) == usRegAddr)
        {
            // 2406 RO 液冷机故障码 UINT16 1 0
            usVal = pDev->m_uFaultCode;
        }
        else if ((LC_REG_INT_MIN+6) == usRegAddr)
        {
            // 2407 RO 液冷压缩机转速 UINT16 1 0
            usVal = pDev->m_uEngineSpeed;
        }
        else if ((LC_REG_INT_MIN+7) == usRegAddr)
        {
            // 2408 RO 液冷水泵转速 UINT16 1 0
            usVal = pDev->m_uPumpSpeed;
        }
        else if ((LC_REG_INT_MIN+8) == usRegAddr)
        {
            // 2409 RO 调试开关状态 UINT16 1 0 0--关闭，1--开启
            usVal = pDev->m_uDebugState;
        }
        else if ((LC_REG_INT_MIN+9) == usRegAddr)
        {
            // 2410 RO 液冷机水泵状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uPumpState1;
        }
        else
        {
            //2411~2600 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= LC_REG_FLT_MIN && usRegAddr <= LC_REG_FLT_MAX)
    {
        //读液冷的FLOAT数据(200个)
        iRetVal = 2;

        if ((LC_REG_FLT_MIN+0) == usRegAddr)
        {
            // 2601 RO 供(出)水温度 FLOAT 1 0 ℃
            fVal = pDev->m_fOutWaterTemp;
        }
        else if ((LC_REG_FLT_MIN+2) == usRegAddr)
        {
            // 2603 RO 回(进)水温度 FLOAT 1 0 ℃
            fVal = pDev->m_fInWaterTemp;
        }
        else if ((LC_REG_FLT_MIN+4) == usRegAddr)
        {
            // 2605 RO 供(出)水压力 FLOAT 1 0 bar
            fVal = pDev->m_fOutWaterPres;
        }
        else if ((LC_REG_FLT_MIN+6) == usRegAddr)
        {
            // 2607 RO 回(进)水压力 FLOAT 1 0 bar
            fVal = pDev->m_fInWaterPres;
        }
        else if ((LC_REG_FLT_MIN+8) == usRegAddr)
        {
            // 2609 RO 环境温度 FLOAT 1 0 ℃
            fVal = pDev->m_fEnvTemp;
        }
        else if ((LC_REG_FLT_MIN+10) == usRegAddr)
        {
            // 2611 RO 制冷开启温度 FLOAT 1 0 ℃
            fVal = pDev->m_fCoolStartTemp;
        }
        else if ((LC_REG_FLT_MIN+12) == usRegAddr)
        {
            // 2613 RO 制冷停止温度  FLOAT 1 0 ℃
            fVal = pDev->m_fCoolStopTemp;
        }
        else if ((LC_REG_FLT_MIN+14) == usRegAddr)
        {
            // 2615 RO 制冷回差温度 FLOAT 1 0 ℃
            fVal = pDev->m_fCoolDiffTemp;
        }
        else if ((LC_REG_FLT_MIN+16) == usRegAddr)
        {
            // 2617 RO 制热开启温度 FLOAT 1 0 ℃
            fVal = pDev->m_fHeatStartTemp;
        }
        else if ((LC_REG_FLT_MIN+18) == usRegAddr)
        {
            // 2619 RO 制热停止温度  FLOAT 1 0 ℃
            fVal = pDev->m_fHeatStopTemp;
        }
        else if ((LC_REG_FLT_MIN+20) == usRegAddr)
        {
            // 2621 RO 制热回差温度 FLOAT 1 0 ℃
            fVal = pDev->m_fHeatDiffTemp;
        }
        else if ((LC_REG_FLT_MIN+22) == usRegAddr)
        {
            // 2623 RO 除湿开启湿度  FLOAT 1 0 %
            fVal = pDev->m_fDryStartHumi;
        }
        else if ((LC_REG_FLT_MIN+24) == usRegAddr)
        {
            // 2625 RO 除湿停止湿度  FLOAT 1 0 %
            fVal = pDev->m_fDryStopHumi;
        }
        else if ((LC_REG_FLT_MIN+26) == usRegAddr)
        {
            // 2627 RO 除湿回差湿度  FLOAT 1 0 %
            fVal = pDev->m_fDryDiffHumi;
        }
        else if ((LC_REG_FLT_MIN+28) == usRegAddr)
        {
            // 2629 RO 调试下的单体最大温度  FLOAT 1 0 ℃
            fVal = pDev->m_fDebugSglMaxTemp;
        }
        else if ((LC_REG_FLT_MIN+30) == usRegAddr)
        {
            // 2631 RO 调试下的单体最小温度  FLOAT 1 0 ℃
            fVal = pDev->m_fDebugSglMinTemp;
        }
        else if ((LC_REG_FLT_MIN+32) == usRegAddr)
        {
            // 2633 RO 调试下的单体平均温度  FLOAT 1 0 ℃
            fVal = pDev->m_fDebugSglAvgTemp;
        }
        else if ((LC_REG_FLT_MIN+34) == usRegAddr)
        {
            // 2635 RO 调试下的单体最大温差  FLOAT 1 0 ℃
            fVal = pDev->m_fDebugSglMaxTempDiff;
        }
        else
        {
            // 2637~2999 预留
            fVal = 0.0;
        }
    }
    else if (usRegAddr >= LC_REG_SET_MIN && usRegAddr <= LC_REG_SET_MAX)
    {
        //读液冷的下设的数据(200个)
        iRetVal = 1;

        if ((LC_REG_SET_MIN+0) == usRegAddr)
        {
            // 32401 W 控制模式 UINT16 1 0 0BMS控制 1自动控制 2强制控制
            usVal = pDev->m_uSetControlMode; //控制模式 0BMS控制 1自动控制 2强制控制
        }
        else if ((LC_REG_SET_MIN+1) == usRegAddr)
        {
            // 32402 W 开关机 UINT16 1 0 0关机 1开机
            usVal = pDev->m_uSetMachineEnable; //开关机 0关机 1开机
        }
        else if ((LC_REG_SET_MIN+2) == usRegAddr)
        {
            // 32403 W 工作状态 UINT16 1 0 0待机 1制冷 2制热 3循环 4自动
            usVal = pDev->m_uSetWorkState; //工作模式 0待机 1制冷 2制热 3循环 4自动
        }
        else if ((LC_REG_SET_MIN+3) == usRegAddr)
        {
            // 32404 W 下设目标温度 UINT16 0.01 -100 ℃
            // "实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetTargetTemp+100)*100; //目标温度
        }
        else if ((LC_REG_SET_MIN+4) == usRegAddr)
        {
            // 32402 W 下设的制冷开启温度 UINT16 0.01 -100 ℃
            //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetCoolStartTemp+100)*100;
        }
        else if ((LC_REG_SET_MIN+5) == usRegAddr)
        {
            // 32406 W 下设的制冷停止温度 UINT16 0.01 -100 ℃
            //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetCoolStopTemp+100)*100;
        }
        else if ((LC_REG_SET_MIN+6) == usRegAddr)
        {
            // 32407 W 下设的制冷回差温度 UINT16 0.01 -100 ℃
            //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetCoolDiffTemp+100)*100;
        }
        else if ((LC_REG_SET_MIN+7) == usRegAddr)
        {
            // 32408 W 下设的制热开启温度 UINT16 0.01 -100 ℃
            //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetHeatStartTemp+100)*100;
        }
        else if ((LC_REG_SET_MIN+8) == usRegAddr)
        {
            // 32409 W 下设的制热停止温度 UINT16 0.01 -100 ℃
            //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetHeatStopTemp+100)*100;
        }
        else if ((LC_REG_SET_MIN+9) == usRegAddr)
        {
            // 32410 W 下设的制热回差温度 UINT16 0.01 -100 ℃
            //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetHeatDiffTemp+100)*100;
        }
        else if ((LC_REG_SET_MIN+10) == usRegAddr)
        {
            // 32411 W 下设的除湿开启湿度 UINT16 0.01 -100 %
            //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetDryStartHumi+100)*100;
        }
        else if ((LC_REG_SET_MIN+11) == usRegAddr)
        {
            // 32412 W 下设的除湿停止湿度 UINT16 0.01 -100 %
            //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetDryStopHumi+100)*100;
        }
        else if ((LC_REG_SET_MIN+12) == usRegAddr)
        {
            // 32413 W 下设的除湿回差湿度 UINT16 0.01 -100 %
            //"实际值=寄存器值*0.01-100 寄存器值=(实际值+100)*100 实际值范围:-100~100"
            usVal = (quint16) (pDev->m_fSetDryDiffHumi+100)*100;
        }
        else
        {
            //32414~32600 预留
            usVal = 0;
        }
    }

    return iRetVal;
}

int CModbusFactory::getRegValPcs(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_PCS_NUM)
    {
        return -1;
    }

    CPcsData* pDev = 0;
    pDev = m_pRtdb->getPcs(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= PCS_REG_INT_MIN && usRegAddr <= PCS_REG_INT_MAX)
    {
        //读PCS的UINT16数据(200个)
        iRetVal = 1;

        if ((PCS_REG_INT_MIN+0) == usRegAddr)
        {
            // 3001 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((PCS_REG_INT_MIN+1) == usRegAddr)
        {
            // 3002 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((PCS_REG_INT_MIN+2) == usRegAddr)
        {
            // 3003 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((PCS_REG_INT_MIN+3) == usRegAddr)
        {
            // 3004 RO 故障状态 UINT16 1 0 0正常 1故障
            usVal = pDev->m_uFaultState;
        }
        else if ((PCS_REG_INT_MIN+4) == usRegAddr)
        {
            // 3005 RO 工作状态 UINT16 1 0 0--待机 1--充电 2--放电
            usVal = 0;
        }
        else if ((PCS_REG_INT_MIN+5) == usRegAddr)
        {
            // 3006 RO 并离网状态 UINT16 1 0 0-并网 1-离网
            usVal = pDev->m_uOnOffGridState;
        }
        else if ((PCS_REG_INT_MIN+6) == usRegAddr)
        {
            // 3007 RO 硬件故障字1 UINT16 详情见右侧附录
            usVal = pDev->m_uWordHd;
        }
        else if ((PCS_REG_INT_MIN+7) == usRegAddr)
        {
            // 3008 RO 硬件故障字2 UINT16 详情见右侧附录
            usVal = pDev->m_uWordHdSec;
        }
        else if ((PCS_REG_INT_MIN+8) == usRegAddr)
        {
            // 3009 RO 电网故障字 UINT16 详情见右侧附录
            usVal = pDev->m_uWordNet;
        }
        else if ((PCS_REG_INT_MIN+9) == usRegAddr)
        {
            // 3010 RO 母线故障字 UINT16 详情见右侧附录
            usVal = pDev->m_uWordMother;
        }
        else if ((PCS_REG_INT_MIN+10) == usRegAddr)
        {
            // 3011 RO 交流电容故障字 UINT16 详情见右侧附录
            usVal = pDev->m_uWordAcCap;
        }
        else if ((PCS_REG_INT_MIN+11) == usRegAddr)
        {
            // 3012 RO 系统故障字 UINT16 详情见右侧附录
            usVal = pDev->m_uWordSys;
        }
        else if ((PCS_REG_INT_MIN+12) == usRegAddr)
        {
            // 3013 RO 开关故障字 UINT16 详情见右侧附录
            usVal = pDev->m_uWordSwitch;
        }
        else if ((PCS_REG_INT_MIN+13) == usRegAddr)
        {
            // 3014 RO 其他故障字 UINT16 详情见右侧附录
            usVal = pDev->m_uWordOther;
        }
        else
        {
            // 3015~3200 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= PCS_REG_FLT_MIN && usRegAddr <= PCS_REG_FLT_MAX)
    {
        //读PCS的FLOAT数据(200个)
        iRetVal = 2;

        if ((PCS_REG_FLT_MIN+0) == usRegAddr)
        {
            // 3201 RO 电池电压 FLOAT 1 0 V
            fVal = pDev->m_fDirectVol;
        }
        else if ((PCS_REG_FLT_MIN+2) == usRegAddr)
        {
            // 3203 RO 电池电流 FLOAT 1 0 A
            fVal = pDev->m_fDirectCur;
        }
        else if ((PCS_REG_FLT_MIN+4) == usRegAddr)
        {
            // 3205 RO IGBT温度 FLOAT 1 0 ℃
            fVal = pDev->m_fDeviceTemp;
        }
        else if ((PCS_REG_FLT_MIN+6) == usRegAddr)
        {
            // 3207 RO AB线电压 FLOAT 1 0 V
            fVal = pDev->m_fABLineVol;
        }
        else if ((PCS_REG_FLT_MIN+8) == usRegAddr)
        {
            // 3209 RO BC线电压 FLOAT 1 0 V
            fVal = pDev->m_fBCLineVol;
        }
        else if ((PCS_REG_FLT_MIN+10) == usRegAddr)
        {
            // 3211 RO CA线电压 FLOAT 1 0 V
            fVal = pDev->m_fCALineVol;
        }
        else if ((PCS_REG_FLT_MIN+12) == usRegAddr)
        {
            // 3213 RO A相电流 FLOAT 1 0 A
            fVal = pDev->m_fAPhaseCur;
        }
        else if ((PCS_REG_FLT_MIN+14) == usRegAddr)
        {
            // 3215 RO B相电流 FLOAT 1 0 A
            fVal = pDev->m_fBPhaseCur;
        }
        else if ((PCS_REG_FLT_MIN+16) == usRegAddr)
        {
            // 3217 RO C相电流 FLOAT 1 0 A
            fVal = pDev->m_fCPhaseCur;
        }
        else if ((PCS_REG_FLT_MIN+18) == usRegAddr)
        {
            // 3219 RO A相有功功率 FLOAT 1 0 kW
            fVal = pDev->m_fAPhaseActPower;
        }
        else if ((PCS_REG_FLT_MIN+20) == usRegAddr)
        {
            // 3221 RO B相有功功率 FLOAT 1 0 kW
            fVal = pDev->m_fBPhaseActPower;
        }
        else if ((PCS_REG_FLT_MIN+22) == usRegAddr)
        {
            // 3223 RO C相有功功率 FLOAT 1 0 kW
            fVal = pDev->m_fCPhaseActPower;
        }
        else if ((PCS_REG_FLT_MIN+24) == usRegAddr)
        {
            // 3225 RO 总有功功率 FLOAT 1 0 kW
            fVal = pDev->m_fTotalActPower;
        }
        else if ((PCS_REG_FLT_MIN+26) == usRegAddr)
        {
            // 3227 RO A相无功功率 FLOAT 1 0 kVar
            fVal = pDev->m_fAPhaseReactPower;
        }
        else if ((PCS_REG_FLT_MIN+28) == usRegAddr)
        {
            // 3229 RO B相无功功率 FLOAT 1 0 kVar
            fVal = pDev->m_fBPhaseReactPower;
        }
        else if ((PCS_REG_FLT_MIN+30) == usRegAddr)
        {
            // 3231 RO C相无功功率 FLOAT 1 0 kVar
            fVal = pDev->m_fCPhaseReactPower;
        }
        else if ((PCS_REG_FLT_MIN+32) == usRegAddr)
        {
            // 3233 RO 总无功功率 FLOAT 1 0 kVar
            fVal = pDev->m_fTotalReactPower;
        }
        else if ((PCS_REG_FLT_MIN+34) == usRegAddr)
        {
            // 3235 RO A相视在功率 FLOAT 1 0 kVA
            fVal = pDev->m_fAPhaseApprPower;
        }
        else if ((PCS_REG_FLT_MIN+36) == usRegAddr)
        {
            // 3237 RO B相视在功率 FLOAT 1 0 kVA
            fVal = pDev->m_fBPhaseApprPower;
        }
        else if ((PCS_REG_FLT_MIN+38) == usRegAddr)
        {
            // 3239 RO C相视在功率 FLOAT 1 0 kVA
            fVal = pDev->m_fCPhaseApprPower;
        }
        else if ((PCS_REG_FLT_MIN+40) == usRegAddr)
        {
            // 3241 RO 总视在功率 FLOAT 1 0 kVA
            fVal = pDev->m_fTotalApprPower;
        }
        else if ((PCS_REG_FLT_MIN+42) == usRegAddr)
        {
            // 3243 RO 功率因数	FLOAT	1	0
            fVal = pDev->m_fTotalPowerFactor;
        }
        else if ((PCS_REG_FLT_MIN+44) == usRegAddr)
        {
            // 3245 RO 电网频率 FLOAT 1 0 HZ
            fVal = pDev->m_fTotalFreq;
        }
        else if ((PCS_REG_FLT_MIN+46) == usRegAddr)
        {
            // 3247 RO 累积充电量 FLOAT 1 0 kWh
            fVal = pDev->m_fAcTotalChgEq;
        }
        else if ((PCS_REG_FLT_MIN+48) == usRegAddr)
        {
            // 3249 RO 累积放电量 FLOAT 1 0 kWh
            fVal = pDev->m_fAcTotalDisChgEq;
        }
        else
        {
            // 3251~3599 预留
            fVal = 0.0;
        }
    }
    else if (usRegAddr >= PCS_REG_SET_MIN && usRegAddr <= PCS_REG_SET_MAX)
    {
        //读PCS的下设的UINT16数据(200个)
        iRetVal = 1;

        if ((PCS_REG_SET_MIN+0) == usRegAddr)
        {
            // 33001 W 设置开关机 UINT16 1 0 0无动作,1关机,2开机,默认为0
            usVal = pDev->m_uSetSwitchState;
        }
        else if ((PCS_REG_SET_MIN+1) == usRegAddr)
        {
            // 33002 W 设置控制模式 UINT16 1 0 "1-就地手动;2-就地曲线;3-就地电流;4-远程曲线(云平台);5-就地自动;6:就地自定义;7:第三方远程(其他ems)。"
            usVal = pDev->m_uSetRunMode;
        }
        else if ((PCS_REG_SET_MIN+2) == usRegAddr)
        {
            // 33003 W 设置并离网 UINT16 1 0 0离网,1并网,2稳压
            usVal = pDev->m_uSetOnOffGridState;
        }
        else if ((PCS_REG_SET_MIN+3) == usRegAddr)
        {
            // 33004 W 设置充电的有功功率 UINT16 0.1 0 kW "默认为0，实际值范围：0~6553.5kw"
            if (pDev->m_fSetActPower > 0.0)
            {
                usVal = (quint16) pDev->m_fSetActPower*10;
            }
            else
            {
                usVal = 0;
            }
        }
        else if ((PCS_REG_SET_MIN+4) == usRegAddr)
        {
            // 33005 W 设置放电的有功功率 UINT16 0.1 0 kW "默认为0，实际值范围：0~6553.5kw"
            if (pDev->m_fSetActPower < 0.0)
            {
                usVal = (quint16) qFabs(pDev->m_fSetActPower)*10;
            }
            else
            {
                usVal = 0;
            }
        }
        else if ((PCS_REG_SET_MIN+5) == usRegAddr)
        {
            // 33006 W 设置充电的无功功率 UINT16 0.1 0 kvar "默认为0,实际值范围：0~6553.5kvar"
            if (pDev->m_fSetReactPower > 0.0)
            {
                usVal = (quint16) pDev->m_fSetReactPower*10;
            }
            else
            {
                usVal = 0;
            }
        }
        else if ((PCS_REG_SET_MIN+6) == usRegAddr)
        {
            // 33007 W 设置放电的无功功率 UINT16 0.1 0 kvar "默认为0，实际值范围：0~6553.5kvar"
            if (pDev->m_fSetReactPower < 0.0)
            {
                usVal = (quint16) qFabs(pDev->m_fSetReactPower)*10;
            }
            else
            {
                usVal = 0;
            }
        }
        else if ((PCS_REG_SET_MIN+7) == usRegAddr)
        {
            // 33008 W 设置故障复位 UINT16 1 0 0不动作,1故障复位，默认为0
            usVal = pDev->m_uSetFaultReset;
        }
        else
        {
            // 33009~33200 预留
            usVal = 0;
        }
    }

    return iRetVal;
}

int CModbusFactory::getRegValMeter(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_METER_NUM)
    {
        return -1;
    }

    CMeterData* pDev = 0;
    pDev = m_pRtdb->getMeter(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= METER_REG_INT_MIN && usRegAddr <= METER_REG_INT_MAX)
    {
        //读电表的UINT16数据(200个)
        iRetVal = 1;

        if ((METER_REG_INT_MIN+0) == usRegAddr)
        {
            // 3601 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((METER_REG_INT_MIN+1) == usRegAddr)
        {
            // 3602 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((METER_REG_INT_MIN+2) == usRegAddr)
        {
            // 3603 RO 故障状态 UINT16 1 0 0正常 1故障
            usVal = pDev->m_uFaultState;
        }
        else if ((METER_REG_INT_MIN+3) == usRegAddr)
        {
            // 3604 RO 告警状态 UINT16 1 0
            usVal = pDev->m_uAlarmState;
        }
        else if ((METER_REG_INT_MIN+4) == usRegAddr)
        {
            // 3605 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else
        {
            // 3606~3800 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= METER_REG_FLT_MIN && usRegAddr <= METER_REG_FLT_MAX)
    {
        //读电表的FLOAT数据(200个)
        iRetVal = 2;

        if ((METER_REG_FLT_MIN+0) == usRegAddr)
        {
            // 3801 RO A相电压 FLOAT 1 0 V
            fVal = pDev->m_fAPhaseVol;
        }
        else if ((METER_REG_FLT_MIN+2) == usRegAddr)
        {
            // 3803 RO B相电压 FLOAT 1 0 V
            fVal = pDev->m_fBPhaseVol;
        }
        else if ((METER_REG_FLT_MIN+4) == usRegAddr)
        {
            // 3805 RO C相电压 FLOAT 1 0 V
            fVal = pDev->m_fCPhaseVol;
        }
        else if ((METER_REG_FLT_MIN+6) == usRegAddr)
        {
            // 3807 RO AB线电压 FLOAT 1 0 V
            fVal = pDev->m_fABLineVol;
        }
        else if ((METER_REG_FLT_MIN+8) == usRegAddr)
        {
            // 3809 RO BC线电压 FLOAT 1 0 V
            fVal = pDev->m_fBCLineVol;
        }
        else if ((METER_REG_FLT_MIN+10) == usRegAddr)
        {
            // 3811 RO CA线电压 FLOAT 1 0 V
            fVal = pDev->m_fCALineVol;
        }
        else if ((METER_REG_FLT_MIN+12) == usRegAddr)
        {
            // 3813 RO A相电流 FLOAT 1 0 A
            fVal = pDev->m_fAPhaseCur;
        }
        else if ((METER_REG_FLT_MIN+14) == usRegAddr)
        {
            // 3815 RO B相电流 FLOAT 1 0 A
            fVal = pDev->m_fBPhaseCur;
        }
        else if ((METER_REG_FLT_MIN+16) == usRegAddr)
        {
            // 3817 RO C相电流 FLOAT 1 0 A
            fVal = pDev->m_fCPhaseCur;
        }
        else if ((METER_REG_FLT_MIN+18) == usRegAddr)
        {
            // 3819 RO A相有功功率 FLOAT 1 0 kW
            fVal = pDev->m_fAPhaseActPower;
        }
        else if ((METER_REG_FLT_MIN+20) == usRegAddr)
        {
            // 3821 RO B相有功功率 FLOAT 1 0 kW
            fVal = pDev->m_fBPhaseActPower;
        }
        else if ((METER_REG_FLT_MIN+22) == usRegAddr)
        {
            // 3823 RO C相有功功率 FLOAT 1 0 kW
            fVal = pDev->m_fCPhaseActPower;
        }
        else if ((METER_REG_FLT_MIN+24) == usRegAddr)
        {
            // 3825 RO 总有功功率 FLOAT 1 0 kW
            fVal = pDev->m_fTotalActPower;
        }
        else if ((METER_REG_FLT_MIN+26) == usRegAddr)
        {
            // 3827 RO A相无功功率 FLOAT 1 0 kVar
            fVal = pDev->m_fAPhaseReactPower;
        }
        else if ((METER_REG_FLT_MIN+28) == usRegAddr)
        {
            // 3829 RO B相无功功率 FLOAT 1 0 kVar
            fVal = pDev->m_fBPhaseReactPower;
        }
        else if ((METER_REG_FLT_MIN+30) == usRegAddr)
        {
            // 3831 RO C相无功功率 FLOAT 1 0 kVar
            fVal = pDev->m_fCPhaseReactPower;
        }
        else if ((METER_REG_FLT_MIN+32) == usRegAddr)
        {
            // 3833 RO 总无功功率 FLOAT 1 0 kVar
            fVal = pDev->m_fTotalReactPower;
        }
        else if ((METER_REG_FLT_MIN+34) == usRegAddr)
        {
            // 3835 RO A相视在功率 FLOAT 1 0 kVA
            fVal = pDev->m_fAPhaseApprPower;
        }
        else if ((METER_REG_FLT_MIN+36) == usRegAddr)
        {
            // 3837 RO B相视在功率 FLOAT 1 0 kVA
            fVal = pDev->m_fBPhaseApprPower;
        }
        else if ((METER_REG_FLT_MIN+38) == usRegAddr)
        {
            // 3839 RO C相视在功率 FLOAT 1 0 kVA
            fVal = pDev->m_fCPhaseApprPower;
        }
        else if ((METER_REG_FLT_MIN+40) == usRegAddr)
        {
            // 3841 RO 总视在功率 FLOAT 1 0 kVA
            fVal = pDev->m_fTotalApprPower;
        }
        else if ((METER_REG_FLT_MIN+42) == usRegAddr)
        {
            // 3843 RO A相功率因数 FLOAT 1 0 无
            fVal = pDev->m_fAPhasePowerFactor;
        }
        else if ((METER_REG_FLT_MIN+44) == usRegAddr)
        {
            // 3845 RO B相功率因数 FLOAT 1 0 无
            fVal = pDev->m_fBPhasePowerFactor;
        }
        else if ((METER_REG_FLT_MIN+46) == usRegAddr)
        {
            // 3847 RO C相功率因数 FLOAT 1 0 无
            fVal = pDev->m_fCPhasePowerFactor;
        }
        else if ((METER_REG_FLT_MIN+48) == usRegAddr)
        {
            // 3849 RO 总功率因数 FLOAT 1 0 无
            fVal = pDev->m_fTotalPowerFactor;
        }
        else if ((METER_REG_FLT_MIN+50) == usRegAddr)
        {
            // 3851 RO 频率 FLOAT 1 0 Hz
            fVal = pDev->m_fTotalFreq;
        }
        else if ((METER_REG_FLT_MIN+52) == usRegAddr)
        {
            // 3853 RO 正向有功电能 FLOAT 1 0 kWh
            fVal = pDev->m_fTotalPosActPowerEq;
        }
        else if ((METER_REG_FLT_MIN+54) == usRegAddr)
        {
            // 3855 RO 反向有功电能 FLOAT 1 0 kWh
            fVal = pDev->m_fTotalNegActPowerEq;
        }
        else if ((METER_REG_FLT_MIN+56) == usRegAddr)
        {
            // 3857 RO 正向无功电能 FLOAT 1 0 kWh
            fVal = pDev->m_fTotalPosReactPowerEq;
        }
        else if ((METER_REG_FLT_MIN+58) == usRegAddr)
        {
            // 3859 RO 反向无功电能 FLOAT 1 0 kWh
            fVal = pDev->m_fTotalNegReactPowerEq;
        }
        else if ((METER_REG_FLT_MIN+60) == usRegAddr)
        {
            // 3861 RO 累积充电量 FLOAT 1 0 kWh
            fVal = pDev->m_fTotalChgEq;
        }
        else if ((METER_REG_FLT_MIN+62) == usRegAddr)
        {
            // 3863 RO 累积放电量 FLOAT 1 0 kWh
            fVal = pDev->m_fTotalDisChgEq;
        }
        else if ((METER_REG_FLT_MIN+64) == usRegAddr)
        {
            // 3865 RO 日充电量 FLOAT 1 0 kWh
            fVal = pDev->m_fCurDayChgEq;
        }
        else if ((METER_REG_FLT_MIN+66) == usRegAddr)
        {
            // 3867 RO 日放电量 FLOAT 1 0 kWh
            fVal = pDev->m_fCurDayDisChgEq;
        }
        else
        {
            // 3869~4199 预留
            usVal = 0;
        }
    }

    return iRetVal;
}

int CModbusFactory::getRegValEc(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_EC_NUM)
    {
        return -1;
    }

    CEcData* pDev = 0;
    pDev = m_pRtdb->getEcDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= EC_REG_INT_MIN && usRegAddr <= EC_REG_INT_MAX)
    {
        //读环控的UINT16数据(200个)
        iRetVal = 1;

        if ((EC_REG_INT_MIN+0) == usRegAddr)
        {
            // 4201 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((EC_REG_INT_MIN+1) == usRegAddr)
        {
            // 4202 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((EC_REG_INT_MIN+2) == usRegAddr)
        {
            // 4203 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((EC_REG_INT_MIN+3) == usRegAddr)
        {
            // 4204 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else
        {
            // 4205~4400 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= EC_REG_FLT_MIN && usRegAddr <= EC_REG_FLT_MAX)
    {
        //读环控的FLOAT数据(200个)
        iRetVal = 2;

        // 4401~4799 预留
        fVal = 0;
    }

    return iRetVal;
}

int CModbusFactory::getRegValDoor(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_DOOR_NUM)
    {
        return -1;
    }

    CDoorData* pDev = 0;
    pDev = m_pRtdb->getDoorDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= DOOR_REG_INT_MIN && usRegAddr <= DOOR_REG_INT_MAX)
    {
        //读门禁的UINT16数据(200个)
        iRetVal = 1;

        if ((DOOR_REG_INT_MIN+0) == usRegAddr)
        {
            // 4801 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((DOOR_REG_INT_MIN+1) == usRegAddr)
        {
            // 4802 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((DOOR_REG_INT_MIN+2) == usRegAddr)
        {
            // 4803 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((DOOR_REG_INT_MIN+3) == usRegAddr)
        {
            // 4804 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else
        {
            // 4805~5000 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= DOOR_REG_FLT_MIN && usRegAddr <= DOOR_REG_FLT_MAX)
    {
        //读门禁的FLOAT数据(200个)
        iRetVal = 2;

        // 5001~5399 预留
        fVal = 0;
    }

    return iRetVal;
}

int CModbusFactory::getRegValGas(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_GAS_NUM)
    {
        return -1;
    }

    CGasData* pDev = 0;
    pDev = m_pRtdb->getGasDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= GAS_REG_INT_MIN && usRegAddr <= GAS_REG_INT_MAX)
    {
        //读可燃气体的UINT16数据(200个)
        iRetVal = 1;

        if ((GAS_REG_INT_MIN+0) == usRegAddr)
        {
            // 5401 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((GAS_REG_INT_MIN+1) == usRegAddr)
        {
            // 5402 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((GAS_REG_INT_MIN+2) == usRegAddr)
        {
            // 5403 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((GAS_REG_INT_MIN+3) == usRegAddr)
        {
            // 5404 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else
        {
            // 5405~5600 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= GAS_REG_FLT_MIN && usRegAddr <= GAS_REG_FLT_MAX)
    {
        //读可燃气体的FLOAT数据(200个)
        iRetVal = 2;

        // 5601~5999 预留
        fVal = 0;
    }

    return iRetVal;
}

int CModbusFactory::getRegValDcdc(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_DCDC_NUM)
    {
        return -1;
    }

    CDcdcData* pDev = 0;
    pDev = m_pRtdb->getDcdcDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= DCDC_REG_INT_MIN && usRegAddr <= DCDC_REG_INT_MAX)
    {
        //读DCDC的UINT16数据(200个)
        iRetVal = 1;

        if ((DCDC_REG_INT_MIN+0) == usRegAddr)
        {
            // 6001 RO 通讯状态 UINT16 1 0 0正常,1故障
            usVal = pDev->m_uCommState;
        }
        else if ((DCDC_REG_INT_MIN+1) == usRegAddr)
        {
            // 6002 RO 运行状态 UINT16 1 0 0运行,1停止
            usVal = pDev->m_uRunState;
        }
        else if ((DCDC_REG_INT_MIN+2) == usRegAddr)
        {
            // 6003 RO 故障状态 UINT16 1 0 0正常,1故障
            usVal = pDev->m_uFaultState;
        }
        else if ((DCDC_REG_INT_MIN+3) == usRegAddr)
        {
            // 6004 RO 告警状态 UINT16 1 0 0正常,1告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((DCDC_REG_INT_MIN+4) == usRegAddr)
        {
            // 6005 RO 开关机状态 UINT16 1 0 0已开机,1已关机
            usVal = pDev->m_uSwitchState;
        }
        else if ((DCDC_REG_INT_MIN+5) == usRegAddr)
        {
            // 6006 RO 直流接入故障字1 UINT16 1 0
            usVal = pDev->m_uDcWord1;
        }
        else if ((DCDC_REG_INT_MIN+6) == usRegAddr)
        {
            // 6007 RO 直流接入状态1 UINT16 1 0 0停机，1电池非充非放,2电池充电,3电池放电,4光伏发电
            usVal = pDev->m_uDcState1;
        }
        else if ((DCDC_REG_INT_MIN+7) == usRegAddr)
        {
            // 6008 RO 直流接入故障1 UINT16 1 0 0正常,1故障
            usVal = pDev->m_uDcFault1;
        }
        else if ((DCDC_REG_INT_MIN+8) == usRegAddr)
        {
            // 6009 RO 直流接入告警1 UINT16 1 0 0正常,1告警
            usVal = pDev->m_uDcAlarm1;
        }
        else if ((DCDC_REG_INT_MIN+9) == usRegAddr)
        {
            // 6010 RO 直流接入故障字2 UINT16 1 0
            usVal = pDev->m_uDcWord2;
        }
        else if ((DCDC_REG_INT_MIN+10) == usRegAddr)
        {
            // 6011 RO 直流接入状态2 UINT16 1 0 0停机，1电池非充非放,2电池充电,3电池放电,4光伏发电
            usVal = pDev->m_uDcState2;
        }
        else if ((DCDC_REG_INT_MIN+11) == usRegAddr)
        {
            // 6012 RO 直流接入故障2 UINT16 1 0 0正常,1故障
            usVal = pDev->m_uDcFault2;
        }
        else if ((DCDC_REG_INT_MIN+12) == usRegAddr)
        {
            // 6013 RO 直流接入告警2 UINT16 1 0 0正常,1告警
            usVal = pDev->m_uDcAlarm2;
        }
        else if ((DCDC_REG_INT_MIN+13) == usRegAddr)
        {
            // 6014 RO 直流接入故障字3 UINT16 1 0
            usVal = pDev->m_uDcWord3;
        }
        else if ((DCDC_REG_INT_MIN+14) == usRegAddr)
        {
            // 6015 RO 直流接入状态3 UINT16 1 0 0停机，1电池非充非放,2电池充电,3电池放电,4光伏发电
            usVal = pDev->m_uDcState3;
        }
        else if ((DCDC_REG_INT_MIN+15) == usRegAddr)
        {
            // 6016 RO 直流接入故障3 UINT16 1 0 0正常,1故障
            usVal = pDev->m_uDcFault3;
        }
        else if ((DCDC_REG_INT_MIN+16) == usRegAddr)
        {
            // 6017 RO 直流接入告警3 UINT16 1 0 0正常,1告警
            usVal = pDev->m_uDcAlarm3;
        }
        else if ((DCDC_REG_INT_MIN+17) == usRegAddr)
        {
            // 6018 RO 直流接入故障字4 UINT16 1 0
            usVal = pDev->m_uDcWord4;
        }
        else if ((DCDC_REG_INT_MIN+18) == usRegAddr)
        {
            // 6019 RO 直流接入状态4 UINT16 1 0 0停机，1电池非充非放,2电池充电,3电池放电,4光伏发电
            usVal = pDev->m_uDcState4;
        }
        else if ((DCDC_REG_INT_MIN+19) == usRegAddr)
        {
            // 6020 RO 直流接入故障4 UINT16 1 0 0正常,1故障
            usVal = pDev->m_uDcFault4;
        }
        else if ((DCDC_REG_INT_MIN+20) == usRegAddr)
        {
            // 6021 RO 直流接入告警4 UINT16 1 0 0正常,1告警
            usVal = pDev->m_uDcAlarm4;
        }
        else if ((DCDC_REG_INT_MIN+21) == usRegAddr)
        {
            // 6022 RO 直流接入故障字5 UINT16 1 0
            usVal = pDev->m_uDcWord5;
        }
        else if ((DCDC_REG_INT_MIN+22) == usRegAddr)
        {
            // 6023 RO 直流接入状态5 UINT16 1 0 0停机，1电池非充非放,2电池充电,3电池放电,4光伏发电
            usVal = pDev->m_uDcState5;
        }
        else if ((DCDC_REG_INT_MIN+23) == usRegAddr)
        {
            // 6024 RO 直流接入故障5 UINT16 1 0 0正常,1故障
            usVal = pDev->m_uDcFault5;
        }
        else if ((DCDC_REG_INT_MIN+24) == usRegAddr)
        {
            // 6025 RO 直流接入告警5 UINT16 1 0 0正常,1告警
            usVal = pDev->m_uDcAlarm5;
        }
        else if ((DCDC_REG_INT_MIN+25) == usRegAddr)
        {
            // 6026 RO 直流接入故障字6 UINT16 1 0
            usVal = pDev->m_uDcWord6;
        }
        else if ((DCDC_REG_INT_MIN+26) == usRegAddr)
        {
            // 6027 RO 直流接入状态6 UINT16 1 0 0停机，1电池非充非放,2电池充电,3电池放电,4光伏发电
            usVal = pDev->m_uDcState6;
        }
        else if ((DCDC_REG_INT_MIN+27) == usRegAddr)
        {
            // 6028 RO 直流接入故障6 UINT16 1 0 0正常,1故障
            usVal = pDev->m_uDcFault6;
        }
        else if ((DCDC_REG_INT_MIN+28) == usRegAddr)
        {
            // 6029 RO 直流接入告警6 UINT16 1 0 0正常,1告警
            usVal = pDev->m_uDcAlarm6;
        }
        else
        {
            // 6030~6200 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= DCDC_REG_FLT_MIN && usRegAddr <= DCDC_REG_FLT_MAX)
    {
        //读DCDC的FLOAT数据(200个)
        iRetVal = 2;

        if ((DCDC_REG_FLT_MIN+0) == usRegAddr)
        {
            // 6201 RO 发电量 FLOAT 1 0 kwh
            fVal = pDev->m_fTotalEnergy;
        }
        else if ((DCDC_REG_FLT_MIN+2) == usRegAddr)
        {
            // 6203 RO 高压侧电压 FLOAT 1 0 V
            fVal = pDev->m_fHighVol;
        }
        else if ((DCDC_REG_FLT_MIN+4) == usRegAddr)
        {
            // 6205 RO 高压侧电流 FLOAT 1 0 A
            fVal = pDev->m_fHighCur;
        }
        else if ((DCDC_REG_FLT_MIN+6) == usRegAddr)
        {
            // 6207 RO 高压侧有功功率 FLOAT 1 0 kw
            fVal = pDev->m_fHighActPower;
        }
        else if ((DCDC_REG_FLT_MIN+8) == usRegAddr)
        {
            // 6209 RO 进风口温度 FLOAT 1 0 ℃
            fVal = pDev->m_fInwindTemp;
        }
        else if ((DCDC_REG_FLT_MIN+10) == usRegAddr)
        {
            // 6211 RO 出风口温度 FLOAT 1 0 ℃
            fVal = pDev->m_fOutwindTemp;
        }
        else if ((DCDC_REG_FLT_MIN+12) == usRegAddr)
        {
            // 6213 RO 低压侧电压1 FLOAT 1 0 V
            fVal = pDev->m_fLowVol1;
        }
        else if ((DCDC_REG_FLT_MIN+14) == usRegAddr)
        {
            // 6215 RO 低压侧电流1 FLOAT 1 0 A
            fVal = pDev->m_fLowCur1;
        }
        else if ((DCDC_REG_FLT_MIN+16) == usRegAddr)
        {
            // 6217 RO 低压侧有功功率1 FLOAT 1 0 kw
            fVal = pDev->m_fLowActPower1;
        }
        else if ((DCDC_REG_FLT_MIN+18) == usRegAddr)
        {
            // 6219 RO 低压侧电压2 FLOAT 1 0 V
            fVal = pDev->m_fLowVol2;
        }
        else if ((DCDC_REG_FLT_MIN+20) == usRegAddr)
        {
            // 6221 RO 低压侧电流2 FLOAT 1 0 A
            fVal = pDev->m_fLowCur2;
        }
        else if ((DCDC_REG_FLT_MIN+22) == usRegAddr)
        {
            // 6223 RO 低压侧有功功率2 FLOAT 1 0 kw
            fVal = pDev->m_fLowActPower2;
        }
        else if ((DCDC_REG_FLT_MIN+24) == usRegAddr)
        {
            // 6225 RO 低压侧电压3 FLOAT 1 0 V
            fVal = pDev->m_fLowVol3;
        }
        else if ((DCDC_REG_FLT_MIN+26) == usRegAddr)
        {
            // 6227 RO 低压侧电流3 FLOAT 1 0 A
            fVal = pDev->m_fLowCur3;
        }
        else if ((DCDC_REG_FLT_MIN+28) == usRegAddr)
        {
            // 6229 RO 低压侧有功功率3 FLOAT 1 0 kw
            fVal = pDev->m_fLowActPower3;
        }
        else if ((DCDC_REG_FLT_MIN+30) == usRegAddr)
        {
            // 6231 RO 低压侧电压4 FLOAT 1 0 V
            fVal = pDev->m_fLowVol4;
        }
        else if ((DCDC_REG_FLT_MIN+32) == usRegAddr)
        {
            // 6233 RO 低压侧电流4 FLOAT 1 0 A
            fVal = pDev->m_fLowCur4;
        }
        else if ((DCDC_REG_FLT_MIN+34) == usRegAddr)
        {
            // 6235 RO 低压侧有功功率4 FLOAT 1 0 kw
            fVal = pDev->m_fLowActPower4;
        }
        else if ((DCDC_REG_FLT_MIN+36) == usRegAddr)
        {
            // 6237 RO 低压侧电压5 FLOAT 1 0 V
            fVal = pDev->m_fLowVol5;
        }
        else if ((DCDC_REG_FLT_MIN+38) == usRegAddr)
        {
            // 6239 RO 低压侧电流5 FLOAT 1 0 A
            fVal = pDev->m_fLowCur5;
        }
        else if ((DCDC_REG_FLT_MIN+40) == usRegAddr)
        {
            // 6241 RO 低压侧有功功率5 FLOAT 1 0 kw
            fVal = pDev->m_fLowActPower5;
        }
        else if ((DCDC_REG_FLT_MIN+42) == usRegAddr)
        {
            // 6243 RO 低压侧电压6 FLOAT 1 0 V
            fVal = pDev->m_fLowVol6;
        }
        else if ((DCDC_REG_FLT_MIN+44) == usRegAddr)
        {
            // 6245 RO 低压侧电流6 FLOAT 1 0 A
            fVal = pDev->m_fLowCur6;
        }
        else if ((DCDC_REG_FLT_MIN+46) == usRegAddr)
        {
            // 6247 RO 低压侧有功功率6 FLOAT 1 0 kw
            fVal = pDev->m_fLowActPower6;
        }
        else
        {
            // 6249~6599 预留
            fVal = 0;
        }
    }

    return iRetVal;
}

int CModbusFactory::getRegValCp(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_PILE_NUM)
    {
        return -1;
    }

    CCpData* pDev = 0;
    pDev = m_pRtdb->getCpDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= CP_REG_INT_MIN && usRegAddr <= CP_REG_INT_MAX)
    {
        //读充电桩的UINT16数据(200个)
        iRetVal = 1;

        if ((CP_REG_INT_MIN+0) == usRegAddr)
        {
            // 6601 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((CP_REG_INT_MIN+1) == usRegAddr)
        {
            // 6602 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((CP_REG_INT_MIN+2) == usRegAddr)
        {
            // 6603 RO 故障状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uFaultState;
        }
        else if ((CP_REG_INT_MIN+3) == usRegAddr)
        {
            // 6604 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((CP_REG_INT_MIN+4) == usRegAddr)
        {
            // 6605 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((CP_REG_INT_MIN+5) == usRegAddr)
        {
            // 6606 RO 连接器状态 UINT16 1 0
            usVal = pDev->m_uLinkerState;
        }
        else if ((CP_REG_INT_MIN+6) == usRegAddr)
        {
            // 6607 RO 工作状态 UINT16 1 0
            usVal = pDev->m_uWorkState;
        }
        else if ((CP_REG_INT_MIN+7) == usRegAddr)
        {
            // 6608 RO 错误码 UINT16 1 0
            usVal = pDev->m_uErrorCode;
        }
        else
        {
            // 6605~6800 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= CP_REG_FLT_MIN && usRegAddr <= CP_REG_FLT_MAX)
    {
        //读充电桩的FLOAT数据(200个)
        iRetVal = 2;

        if ((CP_REG_FLT_MIN+0) == usRegAddr)
        {
            // 6801 RO 电池电量 FLOAT 1 0 kwh
            fVal = pDev->m_fBatEnergy;
        }
        else if ((CP_REG_FLT_MIN+2) == usRegAddr)
        {
            // 6803 RO 直流电压 FLOAT 1 0 V
            fVal = pDev->m_fDcVol;
        }
        else if ((CP_REG_FLT_MIN+4) == usRegAddr)
        {
            // 6805 RO 直流电流 FLOAT 1 0 A
            fVal = pDev->m_fDcCur;
        }
        else
        {
            // 6807~7199 预留
            fVal = 0;
        }
    }

    return iRetVal;
}

int CModbusFactory::getRegValDh(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_DH_NUM)
    {
        return -1;
    }

    CDhData* pDev = 0;
    pDev = m_pRtdb->getDhDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= DH_REG_INT_MIN && usRegAddr <= DH_REG_INT_MAX)
    {
        //读除湿的UINT16数据(200个)
        iRetVal = 1;

        if ((DH_REG_INT_MIN+0) == usRegAddr)
        {
            // 7201 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((DH_REG_INT_MIN+1) == usRegAddr)
        {
            // 7202 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((DH_REG_INT_MIN+2) == usRegAddr)
        {
            // 7203 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((DH_REG_INT_MIN+3) == usRegAddr)
        {
            // 7204 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((DH_REG_INT_MIN+4) == usRegAddr)
        {
            // 7205 RO 故障状态 UINT16 1 0 0正常,1故障
            usVal = pDev->m_uFaultState;
        }
        else
        {
            // 7206~7400 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= DH_REG_FLT_MIN && usRegAddr <= DH_REG_FLT_MAX)
    {
        //读除湿的FLOAT数据(200个)
        iRetVal = 2;

        if ((DH_REG_FLT_MIN+0) == usRegAddr)
        {
            // 7401 RO 室内温度 FLOAT 1 0 ℃
            fVal = pDev->m_fInsideTemp;
        }
        else if ((DH_REG_FLT_MIN+2) == usRegAddr)
        {
            // 7403 RO 室内湿度 FLOAT 1 0 %RH
            fVal = pDev->m_fInsideHumi;
        }
        else if ((DH_REG_FLT_MIN+4) == usRegAddr)
        {
            // 7405 RO 室外温度 FLOAT 1 0 ℃
            fVal = pDev->m_fOutsideTemp;
        }
        else if ((DH_REG_FLT_MIN+6) == usRegAddr)
        {
            // 7407 RO 室外湿度 FLOAT 1 0 %RH
            fVal = pDev->m_fOutsideHumi;
        }
        else if ((DH_REG_FLT_MIN+8) == usRegAddr)
        {
            // 7409 RO 已下设的开始温度 FLOAT 1 0 ℃
            fVal = pDev->m_fSetTempStart;
        }
        else if ((DH_REG_FLT_MIN+10) == usRegAddr)
        {
            // 7411 RO 已下设的结束温度 FLOAT 1 0 ℃
            fVal = pDev->m_fSetTempStop;
        }
        else if ((DH_REG_FLT_MIN+12) == usRegAddr)
        {
            // 7413 RO 已下设的温度回差 FLOAT 1 0 ℃
            fVal = pDev->m_fSetTempDiff;
        }
        else if ((DH_REG_FLT_MIN+14) == usRegAddr)
        {
            // 7415 RO 已下设的开始湿度 FLOAT 1 0 %RH
            fVal = pDev->m_fSetHumiStart;
        }
        else if ((DH_REG_FLT_MIN+16) == usRegAddr)
        {
            // 7417 RO 已下设的结束湿度 FLOAT 1 0 %RH
            fVal = pDev->m_fSetHumiStop;
        }
        else if ((DH_REG_FLT_MIN+18) == usRegAddr)
        {
            // 7419 RO 已下设的湿度回差 FLOAT 1 0 %RH
            fVal = pDev->m_fSetHumiDiff;
        }
        else
        {
            // 7421~7799 预留
            fVal = 0;
        }
    }

    return iRetVal;
}

int CModbusFactory::getRegValFan(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_FAN_NUM)
    {
        return -1;
    }

    CFanData* pDev = 0;
    pDev = m_pRtdb->getFanDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= FAN_REG_INT_MIN && usRegAddr <= FAN_REG_INT_MAX)
    {
        //读风扇的UINT16数据(200个)
        iRetVal = 1;

        if ((FAN_REG_INT_MIN+0) == usRegAddr)
        {
            // 7801 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((FAN_REG_INT_MIN+1) == usRegAddr)
        {
            // 7802 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((FAN_REG_INT_MIN+2) == usRegAddr)
        {
            // 7803 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((FAN_REG_INT_MIN+3) == usRegAddr)
        {
            // 7804 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((FAN_REG_INT_MIN+4) == usRegAddr)
        {
            // 7805 RO 故障状态 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uFaultState;
        }
        else
        {
            // 7806~8000 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= FAN_REG_FLT_MIN && usRegAddr <= FAN_REG_FLT_MAX)
    {
        //读风扇的FLOAT数据(200个)
        iRetVal = 2;

        // 8001~8399 预留
        fVal = 0;
    }

    return iRetVal;
}

int CModbusFactory::getRegValSts(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_STS_NUM)
    {
        return -1;
    }

    CStsData* pDev = 0;
    pDev = m_pRtdb->getStsDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= STS_REG_INT_MIN && usRegAddr <= STS_REG_INT_MAX)
    {
        //读STS的UINT16数据(200个)
        iRetVal = 1;

        if ((STS_REG_INT_MIN+0) == usRegAddr)
        {
            // 8401 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((STS_REG_INT_MIN+1) == usRegAddr)
        {
            // 8402 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((STS_REG_INT_MIN+2) == usRegAddr)
        {
            // 8403 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((STS_REG_INT_MIN+3) == usRegAddr)
        {
            // 8404 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((STS_REG_INT_MIN+4) == usRegAddr)
        {
            // 8405 RO 故障状态 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uFaultState;
        }
        else
        {
            // 8406~8600 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= STS_REG_FLT_MIN && usRegAddr <= STS_REG_FLT_MAX)
    {
        //读STS的FLOAT数据(200个)
        iRetVal = 2;

        // 8601~8999 预留
        fVal = 0;
    }

    return iRetVal;
}

int CModbusFactory::getRegValPress(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_PRESS_NUM)
    {
        return -1;
    }

    CPressData* pDev = 0;
    pDev = m_pRtdb->getPressDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= PRESS_REG_INT_MIN && usRegAddr <= PRESS_REG_INT_MAX)
    {
        //读压力传感器的UINT16数据(200个)
        iRetVal = 1;

        if ((PRESS_REG_INT_MIN+0) == usRegAddr)
        {
            // 9001 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((PRESS_REG_INT_MIN+1) == usRegAddr)
        {
            // 9002 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((PRESS_REG_INT_MIN+2) == usRegAddr)
        {
            // 9003 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((PRESS_REG_INT_MIN+3) == usRegAddr)
        {
            // 9004 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((PRESS_REG_INT_MIN+4) == usRegAddr)
        {
            // 9005 RO 故障状态 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uFaultState;
        }
        else
        {
            // 9006~9200 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= PRESS_REG_FLT_MIN && usRegAddr <= PRESS_REG_FLT_MAX)
    {
        //读压力传感器的FLOAT数据(200个)
        iRetVal = 2;

        // 9201~9599 预留
        fVal = 0;
    }

    return iRetVal;
}

int CModbusFactory::getRegValLevel(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_LEVEL_NUM)
    {
        return -1;
    }

    CLevelData* pDev = 0;
    pDev = m_pRtdb->getLevelDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= LEVEL_REG_INT_MIN && usRegAddr <= LEVEL_REG_INT_MAX)
    {
        //读液位传感器的UINT16数据(200个)
        iRetVal = 1;

        if ((LEVEL_REG_INT_MIN+0) == usRegAddr)
        {
            // 9601 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((LEVEL_REG_INT_MIN+1) == usRegAddr)
        {
            // 9602 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((LEVEL_REG_INT_MIN+2) == usRegAddr)
        {
            // 9603 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((LEVEL_REG_INT_MIN+3) == usRegAddr)
        {
            // 9604 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((LEVEL_REG_INT_MIN+4) == usRegAddr)
        {
            // 9605 RO 故障状态 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uFaultState;
        }
        else
        {
            // 9606~9800 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= LEVEL_REG_FLT_MIN && usRegAddr <= LEVEL_REG_FLT_MAX)
    {
        //读液位传感器的FLOAT数据(200个)
        iRetVal = 2;

        // 9801~10199 预留
        fVal = 0;
    }

    return iRetVal;
}

int CModbusFactory::getRegValPv(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_PV_NUM)
    {
        return -1;
    }

    CPvData* pDev = 0;
    pDev = m_pRtdb->getPvDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= PV_REG_INT_MIN && usRegAddr <= PV_REG_INT_MAX)
    {
        //读光伏的UINT16数据(200个)
        iRetVal = 1;

        if ((PV_REG_INT_MIN+0) == usRegAddr)
        {
            // 10201 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((PV_REG_INT_MIN+1) == usRegAddr)
        {
            // 10202 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((PV_REG_INT_MIN+2) == usRegAddr)
        {
            // 10203 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((PV_REG_INT_MIN+3) == usRegAddr)
        {
            // 10204 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((PV_REG_INT_MIN+4) == usRegAddr)
        {
            // 10205 RO 故障状态 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uFaultState;
        }
        else
        {
            // 10206~10400 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= PV_REG_FLT_MIN && usRegAddr <= PV_REG_FLT_MAX)
    {
        //读光伏的FLOAT数据(200个)
        iRetVal = 2;

        // 10401~10799 预留
        fVal = 0;
    }

    return iRetVal;
}

int CModbusFactory::getRegValUps(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_UPS_NUM)
    {
        return -1;
    }

    CUpsData* pDev = 0;
    pDev = m_pRtdb->getUpsDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= UPS_REG_INT_MIN && usRegAddr <= UPS_REG_INT_MAX)
    {
        //读UPS的UINT16数据(200个)
        iRetVal = 1;

        if ((UPS_REG_INT_MIN+0) == usRegAddr)
        {
            // 10801 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((UPS_REG_INT_MIN+1) == usRegAddr)
        {
            // 10802 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((UPS_REG_INT_MIN+2) == usRegAddr)
        {
            // 10803 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((UPS_REG_INT_MIN+3) == usRegAddr)
        {
            // 10804 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((UPS_REG_INT_MIN+4) == usRegAddr)
        {
            // 10805 RO 故障状态 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uFaultState;
        }
        else
        {
            // 10806~11000 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= UPS_REG_FLT_MIN && usRegAddr <= UPS_REG_FLT_MAX)
    {
        //读UPS的FLOAT数据(200个)
        iRetVal = 2;

        // 11001~11399 预留
        fVal = 0;
    }

    return iRetVal;
}

int CModbusFactory::getRegValLed(int iDevIndex, quint16 usRegAddr, quint16& usVal, float& fVal)
{
    if (iDevIndex < 0)
    {
        return -1;
    }
    if (iDevIndex >= MAX_LED_NUM)
    {
        return -1;
    }

    CLedData* pDev = 0;
    pDev = m_pRtdb->getLedDev(iDevIndex);
    if (0 == pDev)
    {
        return -1;
    }

    int iRetVal = 0;
    if (usRegAddr >= LED_REG_INT_MIN && usRegAddr <= LED_REG_INT_MAX)
    {
        //读LED灯的UINT16数据(200个)
        iRetVal = 1;

        if ((LED_REG_INT_MIN+0) == usRegAddr)
        {
            // 11401 RO 通讯故障 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uCommState;
        }
        else if ((LED_REG_INT_MIN+1) == usRegAddr)
        {
            // 11402 RO 开关机状态 UINT16 1 0 0--已关机,1--已开机
            usVal = pDev->m_uSwitchState;
        }
        else if ((LED_REG_INT_MIN+2) == usRegAddr)
        {
            // 11403 RO 运行状态 UINT16 1 0 0--停止,1--运行
            usVal = pDev->m_uRunState;
        }
        else if ((LED_REG_INT_MIN+3) == usRegAddr)
        {
            // 11404 RO 告警状态 UINT16 1 0 0--正常,1--告警
            usVal = pDev->m_uAlarmState;
        }
        else if ((LED_REG_INT_MIN+4) == usRegAddr)
        {
            // 11405 RO 故障状态 UINT16 1 0 0--正常,1--故障
            usVal = pDev->m_uFaultState;
        }
        else
        {
            // 11405~11600 预留
            usVal = 0;
        }
    }
    else if (usRegAddr >= LED_REG_FLT_MIN && usRegAddr <= LED_REG_FLT_MAX)
    {
        //读LED灯的FLOAT数据(200个)
        iRetVal = 2;

        // 11601~11999 预留
        fVal = 0;
    }

    return iRetVal;
}

// -1 - Not find
// 1 - quint16 类型
// 2 - float 类型
int CModbusFactory::getRegValStack(quint16 usRegAddr, CBattStack* pBattStack, quint16& usVal, float& fVal)
{
    if (0 == pBattStack)
	{
		return -1;
	}

	// some variables
	int iRetVal = -1;

	if (0 == usRegAddr) 
	{
        usVal = 1; //版本 0 - A3 1 - V 3.4
		iRetVal = 1;
	}
	else if (1 == usRegAddr)
	{
        usVal = pBattStack->usStackState; //电池堆状态 1 0x1111充满,0x2222放空,0x5555告警,0xAAAA故障,0xBBBB正常
		iRetVal = 1;
	}
	else if (2 == usRegAddr)
	{
        usVal = pBattStack->usInstallBankNum; //安装电池簇数 2
		iRetVal = 1;
	}
	else if (3 == usRegAddr)
	{
        usVal = pBattStack->usBankNumInStack; //电池堆管辖电池簇数 3
		iRetVal = 1;
	}
	else if (4 == usRegAddr)
	{
        usVal = pBattStack->usStackCfgInfo; //电池堆配置信息 4 各电池簇是否投入运行
		iRetVal = 1;
	}
	else if (5 == usRegAddr)
	{
        usVal = pBattStack->usMaxBankSocNo; //簇SOC最大簇号 4
		iRetVal = 1;
	}
	else if (6 == usRegAddr)
	{
        usVal = pBattStack->usMinBankSocNo; //簇SOC最小簇号 5
		iRetVal = 1;
	}
	else if (7 == usRegAddr)
	{
        usVal = pBattStack->usMaxBankVolNo; //簇电压最大簇号 6
		iRetVal = 1;
	}
	else if (8 == usRegAddr)
	{
        usVal = pBattStack->usMinBankVolNo; //簇电压最小簇号 7
		iRetVal = 1;
	}
	else if (9 == usRegAddr)
	{
        usVal = pBattStack->usSglMaxVolBankNo; //最高单体电压电池簇号 8
		iRetVal = 1;
	}
	else if (10 == usRegAddr)
	{
        usVal = pBattStack->usSglMaxVolNoInBank; //最高电压电池所在簇的簇内编号 9
		iRetVal = 1;
	}
	else if (11 == usRegAddr)
	{
        usVal = pBattStack->usSglMinVolBankNo; //最低单体电压电池簇号 10
		iRetVal = 1;
	}
	else if (12 == usRegAddr)
	{
        usVal = pBattStack->usSglMinVolNoInBank; //最低电压电池所在簇的簇内编号 11
		iRetVal = 1;
	}
	else if (13 == usRegAddr)
	{
        usVal = pBattStack->usSglMaxTempBankNo; //最高电池温度电池簇号 12
		iRetVal = 1;
	}
	else if (14 == usRegAddr)
	{
        usVal = pBattStack->usSglMaxTempNoInBank; //最高电池温度所在簇的簇内编号 13
		iRetVal = 1;
	}
	else if (15 == usRegAddr)
	{
        usVal = pBattStack->usSglMinTempBankNo; //最低电池温度电池簇号 14
		iRetVal = 1;
	}
	else if (16 == usRegAddr)
	{
        usVal = pBattStack->usSglMinTempNoInBank; //最低电池温度所在簇的簇内编号 15
		iRetVal = 1;
	}
	else if (17 == usRegAddr)
	{
        usVal = pBattStack->usDI1; //开关量输入-DI1 16 1--闭合， 0--断开
		iRetVal = 1;
	}
	else if (18 == usRegAddr)
	{
        usVal = pBattStack->usDI2; //开关量输入-DI2 17
		iRetVal = 1;
	}
	else if (19 == usRegAddr)
	{
        usVal = pBattStack->usDI3; //开关量输入-DI3 18
		iRetVal = 1;
	}
	else if (20 == usRegAddr)
	{
        usVal = pBattStack->usDI4; //开关量输入-DI4 19
		iRetVal = 1;
	}
    else if (usRegAddr >= 21 && usRegAddr <= 50) //21~50
	{
        //30个数簇值
		usVal = pBattStack->usStackTemp[usRegAddr - 21];
		iRetVal = 1;
	}
    //以上为UINT16类型数据，以下为FLOAT类型数据
	else if (51 == usRegAddr)
	{
        fVal = pBattStack->fStackVol; //电池堆电压 51
		iRetVal = 2;
	}
	else if (53 == usRegAddr)
	{
        fVal = pBattStack->fStackCur; //电池堆电流 53
		iRetVal = 2;
	}
	else if (55 == usRegAddr)
	{
        fVal = pBattStack->fStackSoc; //电池堆SOC 55
		iRetVal = 2;
	}
	else if (57 == usRegAddr)
	{
        fVal = pBattStack->fStackSoh; //电池堆SOH 57
		iRetVal = 2;
	}
	else if (59 == usRegAddr)
	{
        fVal = pBattStack->fStackChargeEQ; //电池堆可充电量 59
		iRetVal = 2;
	}
	else if (61 == usRegAddr)
	{
        fVal = pBattStack->fStackDischargeEQ; //电池堆可放电量 61
		iRetVal = 2;
	}
	else if (63 == usRegAddr)
	{
        fVal = pBattStack->fStackSglChargeEQ; //电池堆单次充电电量 63
		iRetVal = 2;
	}
	else if (65 == usRegAddr)
	{
        fVal = pBattStack->fStackSglDischargeEQ; //电池堆单次放电电量 65
		iRetVal = 2;
	}
	else if (67 == usRegAddr)
	{
        fVal = pBattStack->dblStackChargeEQAdd; //电池堆充电量累加值 67
		iRetVal = 2;
	}
	else if (69 == usRegAddr)
	{
        fVal = pBattStack->dblStackDischargeEQAdd; //电池堆放电量累加值 69
		iRetVal = 2;
	}
	else if (71 == usRegAddr)
	{
        fVal = pBattStack->fSglVolDiffInStack; //单体电压压差极差值 71
		iRetVal = 2;
	}
	else if (73 == usRegAddr)
	{
        fVal = pBattStack->fSglMaxVolInStack; //最高单体电压 73
		iRetVal = 2;
	}
	else if (75 == usRegAddr)
	{
        fVal = pBattStack->fSglMinVolInStack; //最低单体电压 75
		iRetVal = 2;
	}
	else if (77 == usRegAddr)
	{
        fVal = pBattStack->fSglTempDiffInStack; //电池温度温差极差值 77
		iRetVal = 2;
	}
	else if (79 == usRegAddr)
	{
        fVal = pBattStack->fSglMaxTempInStack; //最高电池温度 79
		iRetVal = 2;
	}
	else if (81 == usRegAddr)
	{
        fVal = pBattStack->fSglMinTempInStack; //最低电池温度 81
		iRetVal = 2;
	}
	else if (83 == usRegAddr)
	{
        fVal = pBattStack->fBankSocDiff; //簇SOC差极差值 83
		iRetVal = 2;
	}
	else if (85 == usRegAddr)
	{
        fVal = pBattStack->fBankSocMax; //簇SOC最大 85
		iRetVal = 2;
	}
	else if (87 == usRegAddr)
	{
        fVal = pBattStack->fBankSocMin; //簇SOC最小 87
		iRetVal = 2;
	}
	else if (89 == usRegAddr)
	{
        fVal = pBattStack->fBankVolDiff; //簇电压差极差值 89
		iRetVal = 2;
	}
	else if (91 == usRegAddr)
	{
        fVal = pBattStack->fBankVolMax; //簇电压最大 91
		iRetVal = 2;
	}
	else if (93 == usRegAddr)
	{
        fVal = pBattStack->fBankVolMin; //簇电压最小 93
		iRetVal = 2;
	}
	else if (95 == usRegAddr)
	{
        fVal = pBattStack->fStackAllowMaxChargePower; //电池堆当前允许最大充电功率 95
		iRetVal = 2;
	}
	else if (97 == usRegAddr)
	{
        fVal = pBattStack->fStackAllowMaxDischargePower; //电池堆当前允许最大放电功率 97
		iRetVal = 2;
	}
	else if (99 == usRegAddr)
	{
        fVal = pBattStack->fStackAllowMaxChargeCurrent; //电池堆当前允许最大充电电流 99
		iRetVal = 2;
	}
	else if (101 == usRegAddr)
	{
        fVal = pBattStack->fStackAllowMaxDischargeCurrent; //电池堆当前允许最大放电电流 101
		iRetVal = 2;
	}
	else if (usRegAddr >= 103 && usRegAddr <= 200)
	{
        //49个数簇值
		fVal = pBattStack->fStackTemp[(usRegAddr - 103) / 2];
		iRetVal = 2;
	}
	else if (8001 == usRegAddr)
	{
        usVal = pBattStack->usBMSUpgradeState; //BMS升级状态 8001
		iRetVal = 1;
	}
	else if (8002 == usRegAddr)
	{
        usVal = pBattStack->usBaVersMajor; //BAMS主版本 8002
		iRetVal = 1;
	}
	else if (8003 == usRegAddr)
	{
        usVal = pBattStack->usBaVersMinor;
		iRetVal = 1;
	}
	else if (8004 == usRegAddr)
	{
        usVal = pBattStack->usBaVersRevision;
		iRetVal = 1;
	}
	else if (8005 == usRegAddr)
	{
        usVal = pBattStack->usCompVers1; //簇件版本
		iRetVal = 1;
	}
	else if (8006 == usRegAddr)
	{
        usVal = pBattStack->usCompVers2;
		iRetVal = 1;
	}
	else if (8007 == usRegAddr)
	{
        usVal = pBattStack->usCompVers3;
		iRetVal = 1;
	}
	else if (8008 == usRegAddr)
	{
        usVal = pBattStack->usCompVers4;
		iRetVal = 1;
	}
	else if (8009 == usRegAddr)
	{
        usVal = pBattStack->usCompVers5;
		iRetVal = 1;
	}
	else if (8010 == usRegAddr)
	{
        usVal = pBattStack->usCompVers6;
		iRetVal = 1;
	}
	else if (8011 == usRegAddr)
	{
        usVal = pBattStack->uaBCVersMajor1; //BC主板本号
		iRetVal = 1;
	}
	else if (8012 == usRegAddr)
	{
        usVal = pBattStack->uaBCVersMajor2;
		iRetVal = 1;
	}
	else if (8013 == usRegAddr)
	{
        usVal = pBattStack->uaBCVersMinor1; //BC次板本号
		iRetVal = 1;
	}
	else if (8014 == usRegAddr)
	{
        usVal = pBattStack->uaBCVersMinor2;
		iRetVal = 1;
	}
	else if (8015 == usRegAddr)
	{
        usVal = pBattStack->uaBCBootVers1;
		iRetVal = 1;
	}
	else if (8016 == usRegAddr)
	{
        usVal = pBattStack->uaBCBootVers2;
		iRetVal = 1;
	}
	else if (8017 == usRegAddr)
	{
        usVal = pBattStack->uaBMUVers1;
		iRetVal = 1;
	}
	else if (8018 == usRegAddr)
	{
        usVal = pBattStack->uaBMUVers2;
		iRetVal = 1;
	}

	return iRetVal;
}

// RTU
int CModbusFactory::addModbusCRC2Buffer(char *pData, int iLen)
{
	quint16 usCRC = Modbus_CRC16(pData, iLen);

	return addParam2Buffer(pData + iLen, usCRC);
}


//********************************************************************
// FUCTION:Modbus_CRC16 —— MODBUS RTU CRC16校验生成函数
// VERSION:1	(2010-9-27 14:34:01)
// INPUT:	dat_buf 待校验数值缓存区
// 			dat_len 待校验数值缓存区的长度
// OUTPUT:	CRC16校验值
// EXAMPLE:
// 输入数据 dat_buf指向的数簇为： 0x33, 0x78, 0x98, 0x60, 校验长度为4
// 则输出为：高字节0xE4 低字节0x91
//********************************************************************
quint16 CModbusFactory::Modbus_CRC16(char *dat_buf, quint16 usLen)
{
	/* CRC 高位字节值表 */
	const uchar AUCHCRCHI[256]=
	{
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x00,0x0C1,0x81,0x40,0x01,0x0C0,0x80,0x41,
		0x01,0x0C0,0x80,0x41,0x00,0x0C1,0x81,0x40
	};
	
	/* CRC 低位字节值表 */
	const uchar AUCHCRCLO[256]=
	{
		0,0xC0,0xC1,0x01,0xC3,0x03,0x02,0xC2,
		0xC6,0x06,0x07,0xC7,0x05,0xC5,0xC4,0x04,
		0xCC,0x0C,0x0D,0xCD,0x0F,0xCF,0xCE,0x0E,
		0x0A,0xCA,0xCB,0x0B,0xC9,0x09,0x08,0xC8,
		0xD8,0x18,0x19,0xD9,0x1B,0xDB,0xDA,0x1A,
		0x1E,0xDE,0xDF,0x1F,0xDD,0x1D,0x1C,0xDC,
		0x14,0xD4,0xD5,0x15,0xD7,0x17,0x16,0xD6,
		0xD2,0x12,0x13,0xD3,0x11,0xD1,0xD0,0x10,
		0xF0,0x30,0x31,0xF1,0x33,0xF3,0xF2,0x32,
		0x36,0xF6,0xF7,0x37,0xF5,0x35,0x34,0xF4,
		0x3C,0xFC,0xFD,0x3D,0xFF,0x3F,0x3E,0xFE,
		0xFA,0x3A,0x3B,0xFB,0x39,0xF9,0xF8,0x38,
		0x28,0xE8,0xE9,0x29,0xEB,0x2B,0x2A,0xEA,
		0xEE,0x2E,0x2F,0xEF,0x2D,0xED,0xEC,0x2C,
		0xE4,0x24,0x25,0xE5,0x27,0xE7,0xE6,0x26,
		0x22,0xE2,0xE3,0x23,0xE1,0x21,0x20,0xE0,
		0xA0,0x60,0x61,0xA1,0x63,0xA3,0xA2,0x62,
		0x66,0xA6,0xA7,0x67,0xA5,0x65,0x64,0xA4,
		0x6C,0xAC,0xAD,0x6D,0xAF,0x6F,0x6E,0xAE,
		0xAA,0x6A,0x6B,0xAB,0x69,0xA9,0xA8,0x68,
		0x78,0xB8,0xB9,0x79,0xBB,0x7B,0x7A,0xBA,
		0xBE,0x7E,0x7F,0xBF,0x7D,0xBD,0xBC,0x7C,
		0xB4,0x74,0x75,0xB5,0x77,0xB7,0xB6,0x76,
		0x72,0xB2,0xB3,0x73,0xB1,0x71,0x70,0xB0,
		0x50,0x90,0x91,0x51,0x93,0x53,0x52,0x92,
		0x96,0x56,0x57,0x97,0x55,0x95,0x94,0x54,
		0x9c,0x5c,0x5d,0x9d,0x5f,0x9f,0x9e,0x5e,
		0x5a,0x9a,0x9b,0x5b,0x99,0x59,0x58,0x98,
		0x88,0x48,0x49,0x89,0x4b,0x8b,0x8a,0x4a,
		0x4e,0x8e,0x8f,0x4f,0x8d,0x4d,0x4c,0x8c,
		0x44,0x84,0x85,0x45,0x87,0x47,0x46,0x86,
		0x82,0x42,0x43,0x83,0x41,0x81,0x80,0x40 
	};
	
	uchar j,CH,CL;
	quint16 i;
	CH = 0XFF;
	CL = 0XFF;
	for (i = 0; i < usLen; i++)
	{
		j = dat_buf[i];
		j = CH ^ j;
		CH = CL ^ AUCHCRCHI[j];
		CL = AUCHCRCLO[j];
	}
	
	return(CH * 0x100 + CL);
}

// >= 0 OK 返回值
// -1 参数错误
// -2 校验失败
// -3 功能码不正确
// < 0 处理失败
// 06 寄存器地址  值  CRC
// 10 寄存器地址  修改个数  CRC
int CModbusFactory::analyDatagramRtuPCS(char *pData, int iLen)
{
	if (0 == pData || iLen < 4)
	{
		return -1;
	}

	// some varibales
	int iInedx = 0;
	uchar uaModbusAddr = 0;
	uchar uaFuncCode = 0;

	quint16 usTemp16 = 0;

	// 校验报文是否正确
	iInedx = 0;

	uaModbusAddr = *(uchar*)pData;
	++iInedx;

	uaFuncCode = *(uchar*)(pData + iInedx);
	++iInedx;

	// get CRC
	getParamFromBuffer(pData + iLen - 2, usTemp16);

	if (usTemp16 != Modbus_CRC16(pData, iLen - 2))
	{
		return -2;
	}

	if (6 != uaFuncCode && 16 != uaFuncCode)
	{
		return -3;
	}

	return 0;
}

// >= 0 OK 返回值
// -1 参数错误
// -2 功能码不正确
// -3 长度不对
// < 0 处理失败
//int CModbusFactory::analySetHoldReturnDatagram(char* pRecDataBuf, int iLen)
//{
//	if (0 == pRecDataBuf || iLen < 12)
//	{
//		return -1;
//	}
//
//	// some varibales
//	int iRetVal = 0;
//	int iInedx = 0;
//	quint16 usEvent = 0;
//	quint16 usLen = 0;
//	uchar uaModbusAddr = 0;
//	uchar uaFuncCode = 0;
//	uchar uaByteNum = 0;
//
//	quint16 usTemp16 = 0;
//
//	// 校验报文是否正确
//	iInedx = 0;
//
//	getParamFromBuffer(pRecDataBuf, usEvent);
//	iInedx += 2;
//
//	iInedx += 2; //协议标识
//
//	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
//	iInedx += 2;
//
//	uaModbusAddr = (uchar)*(pRecDataBuf + iInedx);
//	iInedx += 1;
//
//	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
//	iInedx += 1;
//
//	// 字节数
//	uaByteNum = (uchar)*(pRecDataBuf + iInedx);
//	iInedx += 1;
//
//	if (203 != usEvent || pBattBank->uaModbusAddr != uaModbusAddr || iLen != usLen + 6 || usLen != uaByteNum + 3 || 3 != uaFuncCode) //校验失败
//	{
//		return -2;
//	}
//
//	// data  
//	for (quint16 usIndex = 0; usIndex < uaByteNum / 2; ++usIndex) //寄存器
//	{
//		getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
//
//		if (setAlarmHoldRegVal(usIndex + 1, usTemp16, pAlarmParam, pBattBank) < 0)
//		{
//			iRetVal = -5;
//			break;
//		}
//
//		iInedx += 2;
//	}
//
//	return  iRetVal;
//}


// >= 0 OK 返回值
// -1 参数错误
// -2 校验失败
// -3 功能码校验失败
// -4 事务号不正确
// -5 未知步骤

// < 0 处理失败
int CModbusFactory::analyDatagram(int iIndexStep, char* pRecDataBuf, int iLen, CBattBank* pCurBatt)
{
	if (0 == pRecDataBuf || iLen < 9 || 0 == pCurBatt)
	{
		return -1;
	}

	// some varibales
	int iRetVal = 0;
	int iInedx = 0;
	quint16 usEvent = 0;
	quint16 usLen = 0;
	uchar uaModbusAddr = 0;
	uchar uaFuncCode = 0;
	uchar uaByteNum = 0;

	uchar uaTemp8 = 0;
	quint16 usTemp16 = 0;
	float fTemp = 0;

	// 校验报文是否正确
	iInedx = 0;

	getParamFromBuffer(pRecDataBuf, usEvent);
	iInedx += 2;

    iInedx += 2; //协议标识

	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
	iInedx += 2;

	uaModbusAddr = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	// 字节数
	uaByteNum = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

    if (pCurBatt->uaModbusAddr != uaModbusAddr || iLen != usLen + 6 || usLen != uaByteNum + 3) //校验失败
	{
		return -2;
	}

	switch (iIndexStep)
	{
    case 0: //formDatagram(1/*读取告警状态*/, uaAddr, 2, 1, 34, pSendDataBuf); //离散输入寄存器 1~50
		if (2 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (1 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			// 7 字节
            uaTemp8 = (uchar)*(pRecDataBuf + iInedx); //1~8
			iInedx += 1;

            pCurBatt->aSglVolUpLimitAlarm = (char)(uaTemp8 & 0x01); //单体电压过高告警 1
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aSglVolDownLimitAlarm = (char)(uaTemp8 & 0x01); //单体电压过低告警 2
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aSglTempUpLimitAlarm = (char)(uaTemp8 & 0x01); //单体温度过高告警 3
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aSglTempDownLimitAlarm = (char)(uaTemp8 & 0x01); //单体温度过低告警 4
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aSglVolUpLimitProt = (char)(uaTemp8 & 0x01); //单体电压过高保护 5
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aSglVolDownLimitProt = (char)(uaTemp8 & 0x01); //单体电压过低保护 6
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aSglTempUpLimitProt = (char)(uaTemp8 & 0x01); //单体温度过高保护 7
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aSglTempDownLimitProt = (char)(uaTemp8 & 0x01); //单体温度过低保护 8
            uaTemp8 = uaTemp8 >> 1;

            uaTemp8 = (uchar)*(pRecDataBuf + iInedx); //9~16
			iInedx += 1;

            pCurBatt->aBankVolUpLimitAlarm = (char)(uaTemp8 & 0x01); //簇电压过高告警 9
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aBankVolDownLimitAlarm = (char)(uaTemp8 & 0x01); //簇电压过低告警 10
            uaTemp8 = uaTemp8 >> 1;
    //		pCurBatt->aBankCurUpLimitAlarm = (char)(uaTemp8 & 0x01); //簇电流过高告警 11
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aEnvTempUpLimitAlarm = (char)(uaTemp8 & 0x01); //环境温度过高告警 12
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aEnvTempDownLimitAlarm = (char)(uaTemp8 & 0x01); //环境温度过低告警 13
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aBankSocDownLimitAlarm = (char)(uaTemp8 & 0x01); //SOC超下限告警 14
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aBankVolUpLimitProt = (char)(uaTemp8 & 0x01); //簇电压过高保护 15
            uaTemp8 = uaTemp8 >> 1;
            pCurBatt->aBankVolDownLimitProt = (char)(uaTemp8 & 0x01); //簇电压过低保护 16
            uaTemp8 = uaTemp8 >> 1;

            uaTemp8 = (uchar)*(pRecDataBuf + iInedx); //17~24
			iInedx += 1;

        //	pCurBatt->aBankCurUpLimitProt = (char)(uaTemp8 & 0x01); //簇电流过高保护 17
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aEnvTempUpLimitProt = (char)(uaTemp8 & 0x01); //环境温度过高保护 18
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aEnvTempDownLimitProt = (char)(uaTemp8 & 0x01); //环境温度过低保护 19
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBankSocDownLimitProt = (char)(uaTemp8 & 0x01); //SOC超下限保护 20
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBMUConnFaultAlarm = (char)(uaTemp8 & 0x01); //BMU设备连接故障告警 21
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBCMUConnFaultAlarm = (char)(uaTemp8 & 0x01); //BCMU设备连接故障告警 22
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aSglVolUpLimitWarn = (char)(uaTemp8 & 0x01); //单体电压过高预警 23
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aSglVolDownLimitWarn = (char)(uaTemp8 & 0x01); //单体电压过低预警 24
            //uaTemp8 = uaTemp8 >> 1;

            //uaTemp8 = (uchar)*(pRecDataBuf + iInedx); //25~32
			//iInedx += 1;

            //pCurBatt->aSglTempUpLimitWarn = (char)(uaTemp8 & 0x01); //单体温度过高预警 25
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aSglTempDownLimitWarn = (char)(uaTemp8 & 0x01); //单体温度过低预警 26
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBankSocUpLimitAlarm = (char)(uaTemp8 & 0x01); //SOC超上限告警 27
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBankSocUpLimitProt = (char)(uaTemp8 & 0x01); //SOC超上限保护 28
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aPosResDwonLimitProt = (char)(uaTemp8 & 0x01); //正极绝缘内阻下限保护 29
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aNegResDwonLimitProt = (char)(uaTemp8 & 0x01); //负极绝缘内阻下限保护 30
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aPackVolDiffUpLimitAlarm = (char)(uaTemp8 & 0x01); //箱压差上限告警 31
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aPackVolDiffUpLimitProt = (char)(uaTemp8 & 0x01); //箱压差上限保护 32
            //uaTemp8 = uaTemp8 >> 1;

            //uaTemp8 = (uchar)*(pRecDataBuf + iInedx); //33~40
			//iInedx += 1;

            //pCurBatt->aPackTempDiffUpLimitAlarm = (char)(uaTemp8 & 0x01); //箱温差上限告警 33
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aPackTempDiffUpLimitProt = (char)(uaTemp8 & 0x01); //箱温差上限保护 34
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBankVolUpLimitWarn = (char)(uaTemp8 & 0x01); //簇电压过高预警 35
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBankVolDownLimitWarn = (char)(uaTemp8 & 0x01); //簇电压过低预警 36
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBankCurUpLimitWarn = (char)(uaTemp8 & 0x01); //簇电流过高预警 37
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aEnvTempUpLimitWarn = (char)(uaTemp8 & 0x01); //环境温度过高预警 38
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aEnvTempDownLimitWarn = (char)(uaTemp8 & 0x01); //环境温度过低预警 39
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBankSocUpLimitWarn = (char)(uaTemp8 & 0x01); //SOC超上限预警 40
            //uaTemp8 = uaTemp8 >> 1;

            //uaTemp8 = (uchar)*(pRecDataBuf + iInedx); //41~48
			//iInedx += 1;

            //pCurBatt->aBankSocDownLimitWarn = (char)(uaTemp8 & 0x01); //SOC超下限预警 41
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aPackVolDiffUpLimitWarn = (char)(uaTemp8 & 0x01); //箱压差上限预警 42
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aPackTempDiffUpLimitWarn = (char)(uaTemp8 & 0x01); //箱温差上限预警 43
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBkwdSglVolReptProt = (char)(uaTemp8 & 0x01); //落后电池电压多次保护 44
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aSglVolWireFault = (char)(uaTemp8 & 0x01); //单体电压采集线故障 45
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBankVolWireFault = (char)(uaTemp8 & 0x01); //总压采集线故障 46
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aCurWireFault = (char)(uaTemp8 & 0x01); //电流采集线故障 47
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aTempWireBreak = (char)(uaTemp8 & 0x01); //温度采集断线 48
            //uaTemp8 = uaTemp8 >> 1;

            //uaTemp8 = (uchar)*(pRecDataBuf + iInedx); //49
			//iInedx += 1;

            //pCurBatt->aTempShortCircuit = (char)(uaTemp8 & 0x01); //温度采集短路 49
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBMSFault = (char)(uaTemp8 & 0x01); //BMS设备故障 50
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aBankCurAbnormity = (char)(uaTemp8 & 0x01); //簇电流异常 51
            //uaTemp8 = uaTemp8 >> 1;
            //pCurBatt->aAlarmAvailable = (char)(uaTemp8 & 0x01); //告警信息待获取 52
            //uaTemp8 = uaTemp8 >> 1;

			iRetVal = 0;
        }
		break;

    case 1: //formDatagram(8/*读取电池1~50 电压*/, uaAddr, 4, 1, 100, pSendDataBuf); //输入寄存器 1~99
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (8 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 0; i < 50; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglVol[i] = fTemp; //单体电压
			}

			iRetVal = 0;
		}
		break;
    case 2: //formDatagram(9/*读取电池51~100电压*/, uaAddr, 4, 101, 100, pSendDataBuf); //输入寄存器 101~199
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (9 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 50; i < 100; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglVol[i] = fTemp; //单体电压
			}

			iRetVal = 0;
		}
		break;
    case 3: //formDatagram(10/*读取电池101~150电压*/, uaAddr, 4, 201, 100, pSendDataBuf); //输入寄存器 201~299
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (10 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 100; i < 150; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglVol[i] = fTemp; //单体电压
			}
			iRetVal = 0;
		}
		break;
    case 4: //formDatagram(11/*读取电池151~200电压*/, uaAddr, 4, 301, 100, pSendDataBuf); //输入寄存器 301~399
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (11 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 150; i < 200; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglVol[i] = fTemp; //单体电压
			}
			iRetVal = 0;
		}
		break;
    case 5: //formDatagram(12/*读取电池201~250电压*/, uaAddr, 4, 401, 100, pSendDataBuf); //输入寄存器 401~499
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (12 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 200; i < 250; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglVol[i] = fTemp; //单体电压
			}
			iRetVal = 0;
		}
		break;
    case  6: //formDatagram(13/*读取电池251~300电压*/, uaAddr, 4, 501, 100, pSendDataBuf); //输入寄存器 501~599
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (13 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 250; i < 300; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglVol[i] = fTemp; //单体电压
			}
			iRetVal = 0;
		}
		break;
    case 7: //formDatagram(14/*读取电池301~350电压*/, uaAddr, 4, 601, 100, pSendDataBuf); //输入寄存器 601~699
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (14 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 300; i < 350; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglVol[i] = fTemp; //单体电压
			}
			iRetVal = 0;
		}
		break;
    case 8: //formDatagram(15/*读取电池350~400电压*/, uaAddr, 4, 701, 100, pSendDataBuf); //输入寄存器 701~799
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (15 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 350; i < 400; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglVol[i] = fTemp; //单体电压
			}
			iRetVal = 0;
		}
		break;

    case 9: //formDatagram(16/*读取电池1~50 温度*/, uaAddr, 4, 801, 100, pSendDataBuf); //输入寄存器 801~899
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (16 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 0; i < 50; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglTemp[i] = fTemp; //单体温度
			}

			iRetVal = 0;
		}
		break;
    case 10: //formDatagram(17/*读取电池51~100温度*/, uaAddr, 4, 901, 100, pSendDataBuf); //输入寄存器 901~999
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (17 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 50; i < 100; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglTemp[i] = fTemp; //单体温度
			}
			iRetVal = 0;
		}
		break;
        case 11: //formDatagram(18/*读取电池101~150温度*/, uaAddr, 4, 1001, 100, pSendDataBuf); //输入寄存器 1001~1099
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (18 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 100; i < 150; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglTemp[i] = fTemp; //单体温度
			}
			iRetVal = 0;
		}
		break;
    case 12: //formDatagram(19/*读取电池151~200温度*/, uaAddr, 4, 1101, 100, pSendDataBuf); //输入寄存器 1101~1199
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (19 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 150; i < 200; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglTemp[i] = fTemp; //单体温度
			}
			iRetVal = 0;
		}
		break;
    case 13: //formDatagram(20/*读取电池201~250温度*/, uaAddr, 4, 1201, 100, pSendDataBuf); //输入寄存器 1201~1299
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (20 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 200; i < 250; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglTemp[i] = fTemp; //单体温度
			}
			iRetVal = 0;
		}
		break;
    case 14: //formDatagram(21/*读取电池251~300温度*/, uaAddr, 4, 1301, 100, pSendDataBuf); //输入寄存器 1301~1399
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (21 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 250; i < 300; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglTemp[i] = fTemp; //单体温度
			}
			iRetVal = 0;
		}
		break;
    case 15: //formDatagram(22/*读取电池301~350温度*/, uaAddr, 4, 1401, 100, pSendDataBuf); //输入寄存器 1401~1499
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (22 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 300; i < 350; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglTemp[i] = fTemp; //单体温度
			}
			iRetVal = 0;
		}
		break;
    case 16: //formDatagram(23/*读取电池350~400温度*/, uaAddr, 4, 1501, 100, pSendDataBuf); //输入寄存器 1501~1599
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (23 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 350; i < 400; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglTemp[i] = fTemp; //单体温度
			}
			iRetVal = 0;
		}
		break;

    case 17: //formDatagram(24/*读取电池1~50 Soc*/, uaAddr, 4, 1601, 100, pSendDataBuf); //输入寄存器 1601~1699
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (24 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 0; i < 50; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoc[i] = fTemp; //单体Soc
			}
			iRetVal = 0;
		}
		break;
    case 18: //formDatagram(25/*读取电池51~100Soc*/, uaAddr, 4, 1701, 100, pSendDataBuf); //输入寄存器 1701~1799
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (25 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 50; i < 100; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoc[i] = fTemp; //单体Soc
			}
			iRetVal = 0;
		}
		break;
    case 19: //formDatagram(26/*读取电池101~150Soc*/, uaAddr, 4, 1801, 100, pSendDataBuf); //输入寄存器 1801~1899
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (26 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 100; i < 150; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoc[i] = fTemp; //单体Soc
			}
			iRetVal = 0;
		}
		break;
    case 20: //formDatagram(27/*读取电池151~200Soc*/, uaAddr, 4, 1901, 100, pSendDataBuf); //输入寄存器 1901~1999
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (27 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 150; i < 200; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoc[i] = fTemp; //单体Soc
			}
			iRetVal = 0;
		}
		break;
    case 21: //formDatagram(28/*读取电池201~250Soc*/, uaAddr, 4, 2001, 100, pSendDataBuf); //输入寄存器 2001~2099
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (28 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 200; i < 250; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoc[i] = fTemp; //单体Soc
			}
			iRetVal = 0;
		}
		break;
    case 22: //formDatagram(29/*读取电池251~300Soc*/, uaAddr, 4, 2101, 100, pSendDataBuf); //输入寄存器 2101~2199
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (29 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 250; i < 300; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoc[i] = fTemp; //单体Soc
			}
			iRetVal = 0;
		}
		break;
    case 23: //formDatagram(30/*读取电池301~350Soc*/, uaAddr, 4, 2201, 100, pSendDataBuf); //输入寄存器 2201~2299
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (30 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 300; i < 350; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoc[i] = fTemp; //单体Soc
			}
			iRetVal = 0;
		}
		break;
    case 24: //formDatagram(31/*读取电池350~400Soc*/, uaAddr, 4, 2301, 100, pSendDataBuf); //输入寄存器 2301~2399
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (31 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 350; i < 400; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoc[i] = fTemp; //单体Soc
			}
			iRetVal = 0;
		}
		break;

    case 25: //formDatagram(32/*读取电池1~50 内阻*/, uaAddr, 4, 2401, 100, pSendDataBuf); //输入寄存器 2401~2499
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (32 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 0; i < 50; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglRes[i] = fTemp; //单体内阻
			}

			iRetVal = 0;
		}
		break;
    case 26: //formDatagram(33/*读取电池51~100内阻*/, uaAddr, 4, 2501, 100, pSendDataBuf); //输入寄存器 2501~2599
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (33 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 50; i < 100; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglRes[i] = fTemp; //单体内阻
			}
			iRetVal = 0;
		}
		break;
    case 27: //formDatagram(34/*读取电池101~150内阻*/, uaAddr, 4, 2601, 100, pSendDataBuf); //输入寄存器 2601~2699
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (34 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 100; i < 150; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglRes[i] = fTemp; //单体内阻
			}
			iRetVal = 0;
		}
		break;
    case 28: //formDatagram(35/*读取电池151~200内阻*/, uaAddr, 4, 2701, 100, pSendDataBuf); //输入寄存器 2701~2799
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (35 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 150; i < 200; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglRes[i] = fTemp; //单体内阻
			}
			iRetVal = 0;
		}
		break;
    case 29: //formDatagram(36/*读取电池201~250内阻*/, uaAddr, 4, 2801, 100, pSendDataBuf); //输入寄存器 2801~2899
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (36 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 200; i < 250; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglRes[i] = fTemp; //单体内阻
			}
			iRetVal = 0;
		}
		break;
    case 30: //formDatagram(37/*读取电池251~300内阻*/, uaAddr, 4, 2901, 100, pSendDataBuf); //输入寄存器 2901~2999
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (37 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 250; i < 300; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglRes[i] = fTemp; //单体内阻
			}
			iRetVal = 0;
		}
		break;
    case 31: //formDatagram(38/*读取电池301~350内阻*/, uaAddr, 4, 3001, 100, pSendDataBuf); //输入寄存器 3001~3099
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (38 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 300; i < 350; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglRes[i] = fTemp; //单体内阻
			}
			iRetVal = 0;
		}
		break;
    case 32: //formDatagram(39/*读取电池350~400内阻*/, uaAddr, 4, 3101, 100, pSendDataBuf); //输入寄存器 3101~3199
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (39 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 350; i < 400; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglRes[i] = fTemp; //单体内阻
			}
			iRetVal = 0;
		}
		break;

    case 33: //formDatagram(40/*读取电池1~50 Soh*/, uaAddr, 4, 3201, 100, pSendDataBuf); //输入寄存器 3201~3299
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (40 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 0; i < 50; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoh[i] = fTemp; //单体Soh
			}

			iRetVal = 0;
		}
		break;
    case 34: //formDatagram(41/*读取电池51~100Soh*/, uaAddr, 4, 3301, 100, pSendDataBuf); //输入寄存器 3301~3399
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (41 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 50; i < 100; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoh[i] = fTemp; //单体Soh
			}
			iRetVal = 0;
		}
		break;
    case 35: //formDatagram(42/*读取电池101~150Soh*/, uaAddr, 4, 3401, 100, pSendDataBuf); //输入寄存器 3401~3499
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (42 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 100; i < 150; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoh[i] = fTemp; //单体Soh
			}
			iRetVal = 0;
		}
		break;
    case 36: //formDatagram(43/*读取电池151~200Soh*/, uaAddr, 4, 3501, 100, pSendDataBuf); //输入寄存器 3501~3599
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (43 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 150; i < 200; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoh[i] = fTemp; //单体Soh
			}
			iRetVal = 0;
		}
		break;
    case 37: //formDatagram(44/*读取电池201~250Soh*/, uaAddr, 4, 3601, 100, pSendDataBuf); //输入寄存器 3601~3699
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (44 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 200; i < 250; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoh[i] = fTemp; //单体Soh
			}
			iRetVal = 0;
		}
		break;
        case 38: //formDatagram(45/*读取电池251~300Soh*/, uaAddr, 4, 3701, 100, pSendDataBuf); //输入寄存器 3701~3799
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (45 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 250; i < 300; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoh[i] = fTemp; //单体Soh
			}
			iRetVal = 0;
		}
		break;
        case 39: //formDatagram(46/*读取电池301~350Soh*/, uaAddr, 4, 3801, 100, pSendDataBuf); //输入寄存器 3801~3899
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (46 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 300; i < 350; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoh[i] = fTemp; //单体Soh
			}
			iRetVal = 0;
		}
		break;
        case 40: //formDatagram(47/*读取电池350~400Soh*/, uaAddr, 4, 3901, 100, pSendDataBuf); //输入寄存器 3901~3999
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (47 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			for (int i = 350; i < 400; ++i)
			{
				getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
				iInedx += 4;

                pCurBatt->fSglSoh[i] = fTemp; //单体Soh
			}
			iRetVal = 0;
		}
		break;
        case 41: //formDatagram(48/*读取其他浮点数*/, uaAddr, 4, 4001, 56, pSendDataBuf); //输入寄存器 4001~4055
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (48 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBCMUBankVol = fTemp; //BCMU簇端电压 4001

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBCMUBankCur = fTemp; //BCMU簇电流 4003

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBCMUBankTemp = fTemp; //BCMU环境温度 4005

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBCMUPosRes = fTemp; //BCMU 正极绝缘电阻 4007

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBCMUNegRes = fTemp; //BCMU 负极绝缘电阻 4009

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglAvgVol = fTemp; //单体电压的平均值 4011

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglMaxVol = fTemp; //单电电压的最大值 4013

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglMinVol = fTemp; //单电电压的最小值 4015

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglAvgTemp = fTemp; //单体温度的平均值 4017

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglMaxTemp = fTemp; //单电温度的最大值 4019

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglMinTemp = fTemp; //单电温度的最小值 4021

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglAvgRes = fTemp; //单体平均内阻 4023

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglMaxRes = fTemp; //单体内阻的最大值 4025

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglMinRes = fTemp; //单体内阻的最小值 4027

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglAvgSoc = fTemp; //单体SOC的平均值 4029

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglMaxSoc = fTemp; //单体SOC的最大值 4031

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglMinSoc = fTemp; //单体SOC的最小值 4033

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglAvgSoh = fTemp; //单体SOH的平均值 4035

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglMaxSoh = fTemp; //单体SOH的最大值 4037

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fSglMinSoh = fTemp; //单体SOH的最小值 4039

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankSoc = fTemp; //簇SOC 4041

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankSoh = fTemp; //簇SOH 4043

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankChargeEQ = fTemp; //电池簇可充电量 4045

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankDischargeEQ = fTemp; //电池簇可放电量 4047

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankChargeEQAdd = fTemp; //电池簇累计充电电量 4049

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankDischargeEQAdd = fTemp; //电池簇累计放电电量 4051

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankSglChargeEQAdd = fTemp; //电池簇单次累计充电电量 4053

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankSglDischargeEQAdd = fTemp; //电池簇单次累计放电电量 4055

			iRetVal = 0;
		}
		break;

        case 42: //formDatagram(49/*读取其他短整形数*/, uaAddr, 4, 5001, 25, pSendDataBuf); //输入寄存器 5001~5025
		if (4 != uaFuncCode)
		{
			iRetVal = -3;
		}
		else if (49 != usEvent)
		{
			iRetVal = -4;
		}
		else
		{
			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usSglMaxVolNo = usTemp16; //单电最大电压对应ID号 5001

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usSglMinVolNo = usTemp16; //单电最小电压对应ID号 5002

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usSglMaxTempNo = usTemp16; //单电最大温度对应ID号 5003

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usSglMinTempNo = usTemp16; //单电最小温度对应ID号 5004

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usSglMaxResNo = usTemp16; //单电最大内阻对应ID号 5005

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usSglMinResNo = usTemp16; //单电最小内阻对应ID号 5006

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usSglMaxSocNo = usTemp16; //单电最大SOC对应ID号 5007

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usSglMinSocNo = usTemp16; //单电最小SOC对应ID号 5008

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usSglMaxSohNo = usTemp16; //单电最大SOH对应ID号 5009

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usSglMinSohNo = usTemp16; //单电最小SOH对应ID号 5010

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            pCurBatt->usBankState = usTemp16; //蓄电池簇充放电状态 5011 1 - 开路 2 - 待机 3 - 充电 4 - 放电   // 0—浮充；1—充电；2—放电；3—开路；4—过充；5—欠充；6—开路

			getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			iInedx += 2;
            //pCurBatt->usBankStatePCS = usTemp16; //电池簇状态（告知PCS）	5012 0x1111充满，0x2222放空，0x5555待机，0xaaaa跳机，0xbbbb正常

			//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			//iInedx += 2;
            //pCurBatt->usBCMUInput1 = usTemp16; //BCMU开关状态寄存器Input 1（直流接触器状态） 5013 1--闭合， 0--断开

			//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			//iInedx += 2;
            //pCurBatt->usBCMUInput2 = usTemp16; //BCMU Input 2（熔断器1状态） 5014

			//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			//iInedx += 2;
            //pCurBatt->usBCMUInput3 = usTemp16; //BCMU Input 3（熔断器2状态） 5015

			//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			//iInedx += 2;
            //pCurBatt->usBCMUInput4 = usTemp16; //BCMU Input 4（手动空开状态） 5016

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankMaxChargePower = fTemp; //电池簇最大充电功率 5017

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankMaxDischargePower = fTemp; //电池簇最大放电功率 5019

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankMaxChargeCurrent = fTemp; //电池簇最大充电电流 5021

			//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
			//iInedx += 4;
            //pCurBatt->fBankMaxDischargeCurrent = fTemp; //电池簇最大放电电流 5023

			//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
			//iInedx += 2;
            //pCurBatt->usResTestState = usTemp16; //绝缘检测状态 5025

			iRetVal = 0;
		}
		break;
	default:
		iRetVal = -5;
		break;
	}

	return iRetVal;
}

// 解析电池堆读保持寄存器 0x03 
// >= 0 OK 返回值
// -1 参数错误
// -2 校验失败

// < 0 处理失败
int CModbusFactory::analyStackHoldDatagram(char* pRecDataBuf, int iLen, CBattStack* pStack)
{
	if (0 == pRecDataBuf || iLen < 11 || 0 == pStack)
	{
		return -1;
	}

	// some varibales
	int iInedx = 0;
	quint16 usEvent = 0;
	quint16 usLen = 0;
	uchar uaModbusAddr = 0;
	uchar uaFuncCode = 0;
	uchar uaByteNum = 0;

	quint16 usTemp16 = 0;

	// 校验报文是否正确
	iInedx = 0;

	getParamFromBuffer(pRecDataBuf, usEvent);
	iInedx += 2;

    iInedx += 2; //协议标识

	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
	iInedx += 2;

	uaModbusAddr = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	// 字节数
	uaByteNum = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

    if (202 != usEvent || 1 != uaModbusAddr || iLen != usLen + 6 || usLen != uaByteNum + 3 || 3 != uaFuncCode) //校验失败
	{
		return -2;
	}

	// data  
	getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
	pStack->usDelayBeforeCutCntor = usTemp16;

    return 0;
}

// 解析电池簇读保持寄存器 0x03
// >= 0 OK 返回值
// -1 参数错误
// -2 校验失败
// -5 设置失败
// < 0 处理失败
//int CModbusFactory::analyBankHoldDatagram(char* pRecDataBuf, int iLen, CBattBank* pBattBank, SAlarmParam* pAlarmParam)
//{
//	if (0 == pRecDataBuf || iLen < 11 || 0 == pBattBank || 0 == pAlarmParam)
//	{
//		return -1;
//	}
//
//	// some varibales
//	int iRetVal = 0;
//	int iInedx = 0;
//	quint16 usEvent = 0;
//	quint16 usLen = 0;
//	uchar uaModbusAddr = 0;
//	uchar uaFuncCode = 0;
//	uchar uaByteNum = 0;
//
//	quint16 usTemp16 = 0;
//
//	// 校验报文是否正确
//	iInedx = 0;
//
//	getParamFromBuffer(pRecDataBuf, usEvent);
//	iInedx += 2;
//
//	iInedx += 2; //协议标识
//
//	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
//	iInedx += 2;
//
//	uaModbusAddr = (uchar)*(pRecDataBuf + iInedx);
//	iInedx += 1;
//
//	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
//	iInedx += 1;
//
//	// 字节数
//	uaByteNum = (uchar)*(pRecDataBuf + iInedx);
//	iInedx += 1;
//
//	if (203 != usEvent || pBattBank->uaModbusAddr != uaModbusAddr || iLen != usLen + 6 || usLen != uaByteNum + 3 || 3 != uaFuncCode) //校验失败
//	{
//		return -2;
//	}
//
//	// data  
//	for (quint16 usIndex = 0; usIndex < uaByteNum / 2; ++usIndex) //寄存器
//	{
//		getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
//
//		if (setAlarmHoldRegVal(usIndex + 1, usTemp16, pAlarmParam, pBattBank) < 0)
//		{
//			iRetVal = -5;
//			break;
//		}
//
//		iInedx += 2;
//	}
//
//	return  iRetVal;
//}


// >= 0 OK 返回值
// -1 参数错误
// -2 长度不正确
// -3 功能码不正确

// < 0 处理失败
int CModbusFactory::analyComInputRegDatagram(char* pRecDataBuf, int iLen, quint16* pComInputRegData)
{
	if (0 == pRecDataBuf || iLen < 9 || 0 == pComInputRegData)
	{
		return -1;
	}

	// some varibales
	int iInedx = 0;
	quint16 usEvent = 0;
	quint16 usLen = 0;
	uchar uaModbusAddr = 0;
	uchar uaFuncCode = 0;
	uchar uaByteNum = 0;
	quint16 usTemp16 = 0;

	// 校验报文是否正确
	iInedx = 0;

	getParamFromBuffer(pRecDataBuf, usEvent);
	iInedx += 2;

    iInedx += 2; //协议标识

	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
	iInedx += 2;

	uaModbusAddr = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	// 字节数
	uaByteNum = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

    if (100 != uaModbusAddr || 4 != uaFuncCode || iLen != usLen + 6 || usLen != uaByteNum + 3 || uaByteNum != 200) //校验失败
	{
		return -2;
	}

	if (200 != usEvent)
	{
		return -4;
	}

	for (int i = 0; i < 100; ++i)
	{
		getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		iInedx += 2;

		*(pComInputRegData + i) = usTemp16;
	}

	return 0;
}

// >= 0 OK 返回值
// -1 参数错误
// -2 校验失败
// -3 功能码校验失败
// -4 事务号不正确
// < 0 处理失败
int CModbusFactory::analyStackDatagram(char* pRecDataBuf, int iLen, CBattStack* pStack)
{
	if (0 == pRecDataBuf || iLen < 9 || 0 == pStack)
	{
		return -1;
	}

	// some varibales
	int iRetVal = 0;
	int iInedx = 0;
	quint16 usEvent = 0;
	quint16 usLen = 0;
	uchar uaModbusAddr = 0;
	uchar uaFuncCode = 0;
	uchar uaByteNum = 0;

	quint16 usTemp16 = 0;
	float fTemp = 0;

	// 校验报文是否正确
	iInedx = 0;

	getParamFromBuffer(pRecDataBuf, usEvent);
	iInedx += 2;

    iInedx += 2; //协议标识

	getParamFromBuffer(pRecDataBuf + iInedx, usLen);
	iInedx += 2;

	uaModbusAddr = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	uaFuncCode = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

	// 字节数
	uaByteNum = (uchar)*(pRecDataBuf + iInedx);
	iInedx += 1;

    if (1 != uaModbusAddr || iLen != usLen + 6 || usLen != uaByteNum + 3) //校验失败
	{
		iRetVal = -2;
	}
	else if (4 != uaFuncCode)
	{
		iRetVal = -3;
	}
	else if (201 != usEvent)
	{
		iRetVal = -4;
	}
	else
	{
		getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		iInedx += 2;
        pStack->usStackState = usTemp16; //电池堆状态 2 0x1111充满 0x2222放空 0x5555告警 0xAAAA故障 0xBBBB正常

		getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		iInedx += 4;
        pStack->fStackSoc = fTemp; //电池堆SOC 2

		getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		iInedx += 4;
        pStack->fStackSoh = fTemp; //电池堆SOH 4

		getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		iInedx += 4;
        pStack->fStackChargeEQ = fTemp; //电池堆可充电量  6

		getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		iInedx += 4;
        pStack->fStackDischargeEQ = fTemp; //电池堆可放电量 8

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fStackChargeEQAdd = fTemp; //电池堆充电量累加值 20

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fStackDischargeEQAdd = fTemp; //电池堆放电量累加值 22

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fStackTotalVol = fTemp; //电池堆总电压 24

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fStackTotalCur = fTemp; //电池堆总电流 26

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranParalState1 = usTemp16; //第1支路并联状态 28 2--闭合，2--断开

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranParalState2 = usTemp16; //第2支路并联状态 29

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranParalState3 = usTemp16; //第3支路并联状态 20

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranParalState4 = usTemp16; //第4支路并联状态 21

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranSoc1 = fTemp; //第1支路电池SOC 22

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranSoc2 = fTemp; //第2支路电池SOC 24

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranSoc3 = fTemp; //第3支路电池SOC 26

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranSoc4 = fTemp; //第4支路电池SOC 28

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranCur1 = fTemp; //第1支路当前电流 30

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranCur2 = fTemp; //第2支路当前电流 32

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranCur3 = fTemp; //第3支路当前电流 34

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranCur4 = fTemp; //第4支路当前电流 36

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranState1 = usTemp16; //第1支路电池堆状态 38 0x1111充满 0x2222放空 0x5555告警 0xAAAA故障 0xBBBB正常

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranState2 = usTemp16; //第2支路电池堆状态 39 0x1111充满 0x2222放空 0x5555告警 0xAAAA故障 0xBBBB正常

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranState3 = usTemp16; //第3支路电池堆状态 40 0x1111充满 0x2222放空 0x5555告警 0xAAAA故障 0xBBBB正常

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranState4 = usTemp16; //第4支路电池堆状态 41 0x1111充满 0x2222放空 0x5555告警 0xAAAA故障 0xBBBB正常

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fSglTempCompVol = fTemp; // 单体电池温度补偿电压 42

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usStackStateFull = usTemp16; //电池堆充满 44

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usStackStateEmpty = usTemp16; //电池堆放空 45

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usStackStateTempAlarm = usTemp16; //电池堆温度告警 46

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usStackStateCurAlarm = usTemp16; //电池堆电流告警 47

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usStackStateAllOff = usTemp16; //电池堆接触器全断开 48

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usStackStateFault = usTemp16; //电池堆保护(PCS故障) 49

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fStackSglChargeEQAdd = fTemp; //电池堆单次累计充电电量 50

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fStackSglDischargeEQAdd = fTemp; //电池堆单次累计放电电量 52

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranParalState5 = usTemp16; //第5支路并联状态 54 2--闭合，2--断开

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranParalState6 = usTemp16; //第6支路并联状态 55

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranParalState7 = usTemp16; //第7支路并联状态 56

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranParalState8 = usTemp16; //第8支路并联状态 57
		//
		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranSoc5 = fTemp; //第5支路电池SOC 58

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranSoc6 = fTemp; //第6支路电池SOC 60

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranSoc7 = fTemp; //第7支路电池SOC 62

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranSoc8 = fTemp; //第8支路电池SOC 64

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranCur5 = fTemp; //第5支路当前电流  66

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranCur6 = fTemp; //第6支路当前电流  68

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranCur7 = fTemp; //第7支路当前电流  70

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fBranCur8 = fTemp; //第8支路当前电流  72
		//
		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranState5 = usTemp16; //第5支路电池堆状态  74

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranState6 = usTemp16; //第6支路电池堆状态  75

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranState7 = usTemp16; //第7支路电池堆状态  76

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usBranState8 = usTemp16; //第8支路电池堆状态  77

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fStackMaxChargePower = fTemp; //电池堆最大充电功率 78

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fStackMaxDischargePower = fTemp; //电池堆最大放电功率 80

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fStackMaxChargeCurrent = fTemp; //电池堆最大充电电流 82

		//getParamFromBuffer(pRecDataBuf + iInedx, fTemp);
		//iInedx += 4;
        //pStack->fStackMaxDischargeCurrent = fTemp; //电池堆最大放电电流 84

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usLinkageTripState = usTemp16; //联动跳机模式状态 86

		//getParamFromBuffer(pRecDataBuf + iInedx, usTemp16);
		//iInedx += 2;
        //pStack->usLinkageTripCtrl = usTemp16; //第8支路电池堆状态 87

		iRetVal = 0;
    }

	return iRetVal;
}
